This is my screenshot-output
When i click edit button, then then the edited row data need to display in the above text boxes(attached screenshot).
Here is the aspx file:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<center><div><h4>Student Details</h4></div></center>
<table style="width: 100%;">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
</td>
<td>
</td>
<td>
<asp:TextBox ID="Textusername" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Class"></asp:Label>
</td>
<td>
</td>
<td>
<asp:TextBox ID="Textclass" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="Section"></asp:Label>
</td>
<td>
</td>
<td>
<asp:TextBox ID="Textsection" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label5" runat="server" Text="Address"></asp:Label>
</td>
<td>
</td>
<td>
<asp:TextBox ID="Textaddress" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnsub" runat="server" Text="Submit" OnClick="btnsub_Click" OnClientClick="return register();" />
<asp:Button ID="btnrst" runat="server" Text="Reset" OnClick="btnrst_Click" />
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Column1,Column2,Column3,Column4" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Class" HeaderText="Class" SortExpression="Class" />
<asp:BoundField DataField="Section" HeaderText="Section"
SortExpression="Section" />
<asp:BoundField DataField="Address" HeaderText="Address"
SortExpression="Address" />
<asp:ButtonField ButtonType="Button" CommandName="EditRow" HeaderText="Edit"
ShowHeader="True" Text="Edit" />
<asp:ButtonField ButtonType="Button" CommandName="Delete" HeaderText="Delete"
ShowHeader="True" Text="Delete" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="StoredProcedure2"
SelectCommandType="StoredProcedure">
<DeleteParameters>
<asp:Parameter Name="ID" />
<asp:Parameter Name="Name" />
<asp:Parameter Name="Class" />
<asp:Parameter Name="Section" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="ID" />
<asp:Parameter Name="Name" />
<asp:Parameter Name="Class" />
<asp:Parameter Name="Section" />
</UpdateParameters>
</asp:SqlDataSource>
</asp:Content>
Can anybody help me, how to achieve this one?
Any help would be highly appreciated,
Thanks.,
To achieve the bind value in Form you need to set the TextBox value as GridView rows value within RowCommandEvent:
protected void GridView1_RowCommand(object sender,GridViewCommandEventArgs e)
{
if(e.CommandName =="EditRow")
{
GridViewRow gr = (GridViewRow)((Button)e.CommandSource).NamingContainer;
string id = gr.Cells[0].Text;
txtname.Text =gr.Cells[1].Text;
txtclass.Text=gr.Cells[2].Text;
txtsection.Text =gr.Cells[3].Text;
txtaddress.Text=gr.Cells[4].Text;
}
}
GridView :
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Column1,Column2,Column3,Column4" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Class" HeaderText="Class" SortExpression="Class" />
<asp:BoundField DataField="Section" HeaderText="Section"
SortExpression="Section" />
<asp:BoundField DataField="Address" HeaderText="Address"
SortExpression="Address" />
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:Button runat="server" ID="btnedit" Text="Edit" CommandName="EditRow"></asp:Button>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField ButtonType="Button" CommandName="Delete" HeaderText="Delete"
ShowHeader="True" Text="Delete" />
</Columns>
</asp:GridView>
Or Fetch the row as :
protected void GridView1_RowCommand(object sender,GridViewCommandEventArgs e)
{
if(e.CommandName =="EditRow")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow gr = GridView1.Rows[index];
string id = gr.Cells[0].Text;
txtname.Text =gr.Cells[1].Text;
txtclass.Text=gr.Cells[2].Text;
txtsection.Text =gr.Cells[3].Text;
txtaddress.Text=gr.Cells[4].Text;
}
}
For more Reference :
https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.buttonfield.commandname(v=vs.110).aspx
First, add your GridView and Display Text boxes to Update Panel
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:UpdatePanel ID="updt" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False" >
<ContentTemplate>
<center><div><h4>Student Details</h4></div></center>
<table style="width: 100%;">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
</td>
<td>
</td>
<td>
<asp:TextBox ID="Textusername" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Class"></asp:Label>
</td>
<td>
</td>
<td>
<asp:TextBox ID="Textclass" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="Section"></asp:Label>
</td>
<td>
</td>
<td>
<asp:TextBox ID="Textsection" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label5" runat="server" Text="Address"></asp:Label>
</td>
<td>
</td>
<td>
<asp:TextBox ID="Textaddress" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnsub" runat="server" Text="Submit" OnClick="btnsub_Click" OnClientClick="return register();" />
<asp:Button ID="btnrst" runat="server" Text="Reset" OnClick="btnrst_Click" />
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Column1,Column2,Column3,Column4" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Class" HeaderText="Class" SortExpression="Class" />
<asp:BoundField DataField="Section" HeaderText="Section"
SortExpression="Section" />
<asp:BoundField DataField="Address" HeaderText="Address"
SortExpression="Address" />
<asp:ButtonField ButtonType="Button" CommandName="EditRow" HeaderText="Edit"
ShowHeader="True" Text="Edit" />
<asp:ButtonField ButtonType="Button" CommandName="Delete" HeaderText="Delete"
ShowHeader="True" Text="Delete" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="StoredProcedure2"
SelectCommandType="StoredProcedure">
<DeleteParameters>
<asp:Parameter Name="ID" />
<asp:Parameter Name="Name" />
<asp:Parameter Name="Class" />
<asp:Parameter Name="Section" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="ID" />
<asp:Parameter Name="Name" />
<asp:Parameter Name="Class" />
<asp:Parameter Name="Section" />
</UpdateParameters>
</asp:SqlDataSource>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="GridView1" EventName="RowCommand" />
</Triggers>
</asp:UpdatePanel>
</asp:Content>
This is how to get cell value of edit row on RowCommandEvent
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "EditRow")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[index];
string _name = row.Cells[1].Text;
string _class = row.Cells[2].Text;
string _section = row.Cells[3].Text;
string _Address = row.Cells[4].Text;
//Add this value to your text box here //
}
}
Related
My problem is the next:
I have to make a page which must contain test questions.
I already made it for normal questions, but in the next point, i need a dropdown list in the footer template where the user can choose images names from this list and the textbox get the file path.
The files path is the following:
"~/Dokuments/" + v_tren_dirnev(different folder for every test) + "/Teszt/"
The code for aspx:
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Kerdesek_Valaszok.aspx.cs" Inherits="Kerdesek_Valaszok" %>
<%# Register Src="UserControl/AutoRedirect.ascx" TagName="AutoRedirect" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2"
runat="Server">
<uc1:AutoRedirect ID="AutoRedirect1" runat="server" />
<asp:SqlDataSource ID="SqlDSTreningek" runat="server" ConnectionString="<%$ ConnectionStrings:dbcs %>"SelectCommand="SELECT * FROM [trening] WHERE ([tren_deleted] = #tren_deleted)">
<SelectParameters>
<asp:Parameter DefaultValue="false" Name="tren_deleted" Type="Boolean" />
</SelectParameters>
</asp:SqlDataSource>
<asp:ObjectDataSource ID="odsKerdesek" runat="server" DeleteMethod="DeleteKerdes" InsertMethod="InsertKerdes" SelectMethod="GetAllKerdes" TypeName="trening.KerdesekDataAccessLayer" UpdateMethod="UpdateKerdes">
<SelectParameters>
<asp:Parameter Name="TrenId" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="KerdId" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="KerdTrenId" Type="Int32" />
<asp:Parameter Name="KerdKerdes" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="KerdId" Type="Int32" />
<asp:Parameter Name="KerdKerdes" Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="odsValaszok" runat="server" DeleteMethod="DeleteValasz" InsertMethod="InsertValasz" SelectMethod="GetAllValasz" TypeName="trening.ValaszokDataAccessLayer" UpdateMethod="UpdateValasz">
<SelectParameters>
<asp:Parameter Name="KerdId" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="ValaId" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="ValaKerdId" Type="Int32" />
<asp:Parameter Name="ValaValasz" Type="String" />
<asp:Parameter Name="ValaHelyes" Type="Boolean" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="ValaId" Type="Int32" />
<asp:Parameter Name="ValaValasz" Type="String" />
<asp:Parameter Name="ValaHelyes" Type="Boolean" />
</UpdateParameters>
</asp:ObjectDataSource>
<br />
<table id="kerdesek_valaszok">
<tr>
<td colspan="3">
<h2>Tréning kérdések és válaszok karbantartása</h2>
</td>
</tr>
<tr>
<td colspan="3">
<asp:DropDownList ID="ddlTreningek" runat="server" DataSourceID="SqlDSTreningek" DataTextField="tren_megnevezes" DataValueField="tren_id" Font-Size="Large" AutoPostBack="True" OnDataBound="ddlTreningek_DataBound" OnSelectedIndexChanged="ddlTreningek_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="3">
<asp:GridView ID="gvKerdesek" runat="server" AutoGenerateColumns="False" DataKeyNames="kerd_id" DataSourceID="odsKerdesek" CellPadding="4" ShowFooter="True" ForeColor="#333333" GridLines="None" HorizontalAlign="Center" OnRowCommand="gvKerdesek_RowCommand" OnSelectedIndexChanged="gvKerdesek_SelectedIndexChanged">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="kerd_id" InsertVisible="False" SortExpression="kerd_id" Visible="False">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("kerd_id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("kerd_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="kerd_tren_id" InsertVisible="False" SortExpression="kerd_tren_id" Visible="False">
<EditItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("kerd_tren_id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("kerd_tren_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Kérdések" SortExpression="kerd_kerdes">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("kerd_kerdes") %>' MaxLength="250" Size="100"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvTextBox1" runat="server" ErrorMessage="Kötelező a kérdést megadni!" ValidationGroup="update" ControlToValidate="TextBox1" Text="*" ForeColor="Red"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("kerd_kerdes") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txbNewKerdes" runat="server" MaxLength="250" Size="100"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvTextBox2" runat="server" ErrorMessage="Kötelező az új kérdést megadni" ValidationGroup="insert" ControlToValidate="txbNewKerdes" Text="*" ForeColor="Red"></asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:ImageButton ID="btnUpdateKerdes" runat="server" CausesValidation="True" ValidationGroup="update" CommandName="UpdateKerdes" CommandArgument='<%# Eval("kerd_id") %>' ImageUrl="~/App_Themes/Theme1/update.png" Height="25" ToolTip="Módosítás" />
<asp:ImageButton ID="btnCancelKerdes" runat="server" CausesValidation="false" CommandName="Cancel" ImageUrl="~/App_Themes/Theme1/cancel.png" Height="25" ToolTip="Mégsem" />
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton ID="btnEditKerdes" runat="server" CausesValidation="false" CommandName="EditKerdes" CommandArgument='<%# Eval("kerd_id") %>' ImageUrl="~/App_Themes/Theme1/edit.png" Height="25" ToolTip="Szerkesztés" />
<asp:ImageButton ID="btnSelectKerdes" runat="server" CausesValidation="false" CommandName="SelectKerdes" CommandArgument='<%# Eval("kerd_id") %>' ImageUrl="~/App_Themes/Theme1/select.png" Height="25" ToolTip="Kiválasztás" />
<asp:ImageButton ID="btnDeleteKerdes" runat="server" CausesValidation="false" CommandName="DeleteKerdes" CommandArgument='<%# Eval("kerd_id") %>' ImageUrl="~/App_Themes/Theme1/delete.png" Height="25" ToolTip="Törlés" OnClientClick="return confirm('Biztosan törölni akarja ezt a kérdést és a hozzátartozó válaszokat?');" />
</ItemTemplate>
<FooterTemplate>
<asp:ImageButton ID="btnInsertKerdes" CausesValidation="true" ValidationGroup="insert" runat="server" OnClick="btnInsertKerdes_Click" ImageUrl="~/App_Themes/Theme1/insert.png" Height="25" ToolTip="Új kérdés rögzítése" />
<!--AG dropdown list -->
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
</FooterTemplate>
<ItemStyle Wrap="False" />
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FF9900" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<br />
<asp:ValidationSummary ID="ValidationSummary1" ValidationGroup="insert" runat="server" ForeColor="Red" ShowMessageBox="true" ShowSummary="false" />
<asp:ValidationSummary ID="ValidationSummary2" ValidationGroup="update" runat="server" ForeColor="Red" ShowMessageBox="true" ShowSummary="false" />
<asp:ValidationSummary ID="ValidationSummary3" ValidationGroup="insertValasz" runat="server" ForeColor="Red" ShowMessageBox="true" ShowSummary="false" />
<asp:ValidationSummary ID="ValidationSummary4" ValidationGroup="updateValasz" runat="server" ForeColor="Red" ShowMessageBox="true" ShowSummary="false" />
</td>
</tr>
<tr>
<td colspan="3">
<br />
<asp:GridView ID="gvValaszok" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="vala_id" DataSourceID="odsValaszok" ShowFooter="True" ForeColor="#333333" GridLines="None" EmptyDataText="Nincsenek még válaszok megadva!" HorizontalAlign="Center" OnRowCommand="gvValaszok_RowCommand">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="vala_id" InsertVisible="False" SortExpression="vala_id" Visible="False">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("vala_id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("vala_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="vala_kerd_id" SortExpression="vala_kerd_id" Visible="False">
<EditItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("vala_kerd_id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("vala_kerd_id") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblNewValaKerdId" runat="server" Text='<%# Bind("vala_kerd_id") %>'></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Válaszok" SortExpression="vala_valasz">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("vala_valasz") %>' MaxLength="250" size="100"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("vala_valasz") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txbNewValasz" runat="server" MaxLength="250" size="100"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvTextBox3" runat="server" ErrorMessage="Kötelező az új választ megadni" ValidationGroup="insertValasz" ControlToValidate="txbNewValasz" Text="*" ForeColor="Red"></asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Helyes-e?" SortExpression="vala_helyes">
<EditItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("vala_helyes") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("vala_helyes") %>' Enabled="false" />
</ItemTemplate>
<FooterTemplate>
<asp:CheckBox ID="cbxNewHelyes" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:ImageButton ID="btnUpdateValasz" runat="server" CausesValidation="True" CommandName="UpdateValasz" CommandArgument='<%# Eval("vala_id") %>' ImageUrl="~/App_Themes/Theme1/update.png" Height="25" ToolTip="Módosítás" />
<asp:ImageButton ID="btnCancelValasz" runat="server" CausesValidation="false" CommandName="Cancel" ImageUrl="~/App_Themes/Theme1/cancel.png" Height="25" ToolTip="Mégsem" />
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton ID="btnEditValasz" runat="server" CausesValidation="false" CommandName="Edit" ImageUrl="~/App_Themes/Theme1/edit.png" Height="25" ToolTip="Szerkesztés" />
<asp:ImageButton ID="btnDeleteValasz" runat="server" CausesValidation="false" CommandName="DeleteValasz" CommandArgument='<%# Eval("vala_id") %>' ImageUrl="~/App_Themes/Theme1/delete.png" Height="25" ToolTip="Törlés" OnClientClick="return confirm('Biztosan törölni akarja ezt a választ?');" />
</ItemTemplate>
<FooterTemplate>
<asp:ImageButton ID="btnInsertValasz" CausesValidation="true" ValidationGroup="insertValasz" runat="server" OnClick="btnInsertValasz_Click" ImageUrl="~/App_Themes/Theme1/insert.png" Height="25" ToolTip="Új kérdés rögzítése" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</td>
</tr>
</table>
The code behind this:
public partial class Kerdesek_Valaszok : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnInsertKerdes_Click(object sender, EventArgs e)
{
odsKerdesek.InsertParameters["KerdTrenId"].DefaultValue = ddlTreningek.SelectedValue;
odsKerdesek.InsertParameters["KerdKerdes"].DefaultValue = ((TextBox)gvKerdesek.FooterRow.FindControl("txbNewKerdes")).Text;
odsKerdesek.Insert();
gvKerdesek.DataBind();
}
protected void btnInsertValasz_Click(object sender, EventArgs e)
{
if (gvKerdesek.SelectedRow != null)
{
odsValaszok.InsertParameters["ValaKerdId"].DefaultValue = ((Label)gvValaszok.Rows[0].FindControl("Label3")).Text;
odsValaszok.InsertParameters["ValaValasz"].DefaultValue = ((TextBox)gvValaszok.FooterRow.FindControl("txbNewValasz")).Text;
odsValaszok.InsertParameters["ValaHelyes"].DefaultValue = ((CheckBox)gvValaszok.FooterRow.FindControl("cbxNewHelyes")).Checked.ToString();
odsValaszok.Insert();
gvValaszok.DataBind();
} else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Nincs a kérdés kiválasztva!');", true);
}
}
protected void ddlTreningek_DataBound(object sender, EventArgs e)
{
odsKerdesek.SelectParameters["TrenId"].DefaultValue = ddlTreningek.SelectedValue;
odsKerdesek.Select();
}
protected void ddlTreningek_SelectedIndexChanged(object sender, EventArgs e)
{
odsKerdesek.SelectParameters["TrenId"].DefaultValue = ddlTreningek.SelectedValue;
odsKerdesek.Select();
gvKerdesek.SelectRow(-1);
}
protected void gvKerdesek_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "SelectKerdes")
{
string tmp = e.CommandArgument.ToString();
int selind = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
odsValaszok.SelectParameters["KerdId"].DefaultValue = e.CommandArgument.ToString();
odsValaszok.Select();
gvKerdesek.SelectedIndex = selind;
gvKerdesek.DataBind();
} else if (e.CommandName == "DeleteKerdes")
{
KerdesekDataAccessLayer.DeleteKerdes(Convert.ToInt32(e.CommandArgument));
gvKerdesek.DataBind();
} else if (e.CommandName == "EditKerdes")
{
int rowindex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
gvKerdesek.EditIndex = rowindex;
gvKerdesek.DataBind();
} else if (e.CommandName == "UpdateKerdes")
{
int rowindex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
int kerd_id = Convert.ToInt32(e.CommandArgument);
odsKerdesek.UpdateParameters["KerdId"].DefaultValue = ((Label)gvKerdesek.Rows[rowindex].FindControl("Label1")).Text;
odsKerdesek.UpdateParameters["KerdKerdes"].DefaultValue = ((TextBox)gvKerdesek.Rows[rowindex].FindControl("TextBox1")).Text;
odsKerdesek.Update();
gvKerdesek.EditIndex = -1;
gvKerdesek.DataBind();
}
}
protected void gvValaszok_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "DeleteValasz")
{
ValaszokDataAccessLayer.DeleteValasz(Convert.ToInt32(e.CommandArgument));
gvValaszok.DataBind();
} else if (e.CommandName == "UpdateValasz")
{
int rowindex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
int vala_id = Convert.ToInt32(e.CommandArgument);
odsValaszok.UpdateParameters["ValaId"].DefaultValue = ((Label)gvValaszok.Rows[rowindex].FindControl("Label1")).Text;
odsValaszok.UpdateParameters["ValaValasz"].DefaultValue = ((TextBox)gvValaszok.Rows[rowindex].FindControl("TextBox1")).Text;
odsValaszok.UpdateParameters["ValaHelyes"].DefaultValue = ((CheckBox)gvValaszok.Rows[rowindex].FindControl("CheckBox1")).Checked.ToString();
odsValaszok.Update();
gvValaszok.EditIndex = -1;
gvValaszok.DataBind();
}
}
}
As i told before, the problem is the following. Here is an image for the look and for the asp code. I made an alternative solution, but i really want this too.
The image
I need a code for this:
The dropdown list must contain a folder file names, and after i choose one of them, the text box on the left get filled with the path for the file like this:
~/Dokuments/10001/Teszt/Slide01.JPG
The 10001 can be changed by the top dropdown list, which contains the different test names. If you select a test, then the path changes automatically, so it is not a problem.
And then you can't change the textbox's content only one way, when you choose the default element from the dropdown list.
I have a page that displays a GridView containing an ImageButton TemplateField. My goal is to display an AJAX modal popup when one of those buttons are clicked, along with displaying the row where the button is pressed. The problem is that when I click on a button, it does not show the modal popup. I tried to use this tutorial and read several articles on this site about this issue but to no avail. How to properly fire the button event and show the popup?
Here is the snippet for the gridview:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Width="505px" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="ItemDesc"
SortExpression="ItemDesc" ItemStyle-Width="100px" ItemStyle-Height="100px">
<ItemStyle Height="100px" Width="100px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="Price" SortExpression="Price"
ItemStyle-Width="100px" ItemStyle-Height="100px">
<ItemStyle Height="100px" Width="100px"></ItemStyle>
</asp:BoundField>
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Height="200px"
ImageUrl='<%# Eval("ImagePath") %>' Width="200px" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" CommandName="atc" ImageUrl="~/App_Themes/img/shop/addtocart.png"
Text="Add to Cart" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"/>
</ItemTemplate>
<ControlStyle Height="30px" Width="105px" />
<ItemStyle Width="105px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
...
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="HiddenField1" PopupControlID="Panel1" BackgroundCssClass="modalBg" CancelControlID="btnClose">
</asp:ModalPopupExtender>
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Panel ID="Panel1" runat="server" Width="500" Height="500" Visible="False"
style="background-color:#6f95f4; color:#000000;">
<div class="style1">
<br />
<br />
<br />
<br />
<br />
<table style="width: 90%; height: 71px;">
<tr>
<td>
Item Name</td>
<td>
<asp:Label ID="lblItemName" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td>
Price</td>
<td>
<asp:Label ID="lblPrice" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td>
Quantity</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" Type="Number" Min="1" MaxLength="100"
Width="75px" Height="23px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Total Price</td>
<td>
<asp:Label ID="lblTotalPrice" runat="server" Text="Label"></asp:Label>
</td>
</tr>
</table>
<br />
<br />
<asp:Button ID="btnAddToCart" runat="server" Text="Add to Cart"
onclick="btnAddToCart_Click" />
<br />
<br />
<asp:Button ID="btnClose" runat="server" onclick="btnClose_Click" Text="Close"
Width="199px" />
</div>
</asp:Panel>
And here's my code for the event:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("atc"))
{
ModalPopupExtender1.Show();
//// Retrieve the row index stored in the
//// CommandArgument property.
int index = Convert.ToInt32(e.CommandArgument);
//// Retrieve the row that contains the button
//// from the Rows collection.
GridViewRow row = GridView1.Rows[index];
lblItemName.Text = row.Cells[0].Text;
lblPrice.Text = row.Cells[1].Text;
Response.Write("<script>alert('" + row.Cells[0].Text + "\n" + row.Cells[1].Text + "');</script>");
//// Add code here to add the item to the shopping cart.
}
}
EDIT: Added the panel code.
Try like this:
100% working and Tested
Use onrowcommand="GridView1_RowCommand" for GridView
Use display:none for Your Panel instead of Visible="false"
I Commented your alert(in rowbound) it contains js error
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="505px"
onrowcommand="GridView1_RowCommand"
>
<Columns>
<asp:BoundField DataField="ItemDesc" SortExpression="ItemDesc" ItemStyle-Width="100px"
ItemStyle-Height="100px">
<ItemStyle Height="100px" Width="100px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="Price" SortExpression="Price" ItemStyle-Width="100px"
ItemStyle-Height="100px">
<ItemStyle Height="100px" Width="100px"></ItemStyle>
</asp:BoundField>
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Height="200px" ImageUrl='<%# Eval("ImagePath") %>'
Width="200px" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" CommandName="atc"
CausesValidation="false"
Text="Add to Cart" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
</ItemTemplate>
<ControlStyle Height="30px" Width="105px" />
<ItemStyle Width="105px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<ajax:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="Panel1"
PopupControlID="Panel1" OnOkScript="okClick();"
OnCancelScript="cancelClick();"
OkControlID="btnAddToCart" CancelControlID="btnClose">
</ajax:ModalPopupExtender>
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Panel ID="Panel1" runat="server" Width="500" Height="500"
style="background-color:#6f95f4; color:#000000;display:none">
<div class="style1">
<br />
<br />
<br />
<br />
<br />
<table style="width: 90%; height: 71px;">
<tr>
<td>
Item Name</td>
<td>
<asp:Label ID="lblItemName" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td>
Price</td>
<td>
<asp:Label ID="lblPrice" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td>
Quantity</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" Type="Number" Min="1" MaxLength="100"
Width="75px" Height="23px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Total Price</td>
<td>
<asp:Label ID="lblTotalPrice" runat="server" Text="Label"></asp:Label>
</td>
</tr>
</table>
<br />
<br />
<asp:Button ID="btnAddToCart" runat="server" Text="Add to Cart"
onclick="btnAddToCart_Click" />
<br />
<br />
<asp:Button ID="btnClose" runat="server" onclick="btnClose_Click" Text="Close"
Width="199px" />
</div>
</asp:Panel>
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("atc"))
{
ModalPopupExtender1.Show();
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[index];
ImageButton ImageButton1=(ImageButton)row.FindControl("ImageButton1");
// Response.Write("<script>alert('" + row.Cells[0].Text + "\n" + row.Cells[1].Text + "');</script>"); comment this
}
You didn't set OnRowCommand property of the GridView, so GridView1_RowCommand method won't be fired when you click the image button. Here's how you do it
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Width="505px" DataSourceID="SqlDataSource1"
OnRowCommand="GridView1_RowCommand">
See here for more details.
I have a data field "Gender" (sql data type - bit).
I have created bound the data with if condition to check true-> male otherwise -> female. But it still does not display.
Here is the aspx and code behind code:The gridview shows true/false instead of male/female:
<%# Page Title="Add User" Language="C#" AutoEventWireup="true" CodeFile="adduser.aspx.cs" Inherits="_Default" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<link href="style.css" type="text/css" rel="Stylesheet" />
<script type="text/javascript">
function confirmDelete() {
return confirm("Do you want to delete this record?");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ajax:ToolkitScriptManager ID="toolkit1" runat="server">
</ajax:ToolkitScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table border="0" align="center" cellpadding="2" cellspacing="2" class="maindiv">
<tr><!--Hidden field for EmployeeID reference-->
<td colspan="2"><asp:HiddenField ID="txtHiddenEmpID" Value="0" runat="server" /></td>
</tr>
<tr>
<td>
<span class="asterisk">*</span><asp:Label ID="name" runat="server" Text="Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtEmpName" runat="server" CssClass="box"></asp:TextBox>
<asp:RequiredFieldValidator Display="None" ID="RequiredFieldValidator1" ErrorMessage="Name is required!"
EnableClientScript="true" SetFocusOnError="true" runat="server" ControlToValidate="txtEmpName"
CssClass="error_msg"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="NameValidator" runat="server" ErrorMessage="Name can not contain numeric or special characters."
ControlToValidate="txtEmpName" ValidationExpression="^[A-Za-z ]*$" CssClass="error_msg"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
<span class="asterisk">*</span><asp:Label ID="Label1" runat="server" Text="Address"></asp:Label>
</td>
<td>
<asp:TextBox ID="addressBox" runat="server" CssClass="box"></asp:TextBox>
<asp:RequiredFieldValidator Display="None" ID="AddressValidator" ErrorMessage="Address is required!"
EnableClientScript="true" SetFocusOnError="true" runat="server" ControlToValidate="addressBox"
CssClass="error_msg"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<span class="asterisk">*</span><asp:Label ID="Label2" runat="server" Text="DOB"></asp:Label>
</td>
<td>
<asp:TextBox ID="dobBox" runat="server" CssClass="dob_cal box" ReadOnly="false" ></asp:TextBox>
<ajax:CalendarExtender ID="CalenderExtender1" TargetControlID="dobBox" Format="dd/MM/yyyy"
runat="server">
</ajax:CalendarExtender>
<asp:RequiredFieldValidator Display="None" ID="dobValidator" ErrorMessage="DOB is required!"
EnableClientScript="true" SetFocusOnError="true" runat="server" ControlToValidate="dobBox"
CssClass="error_msg"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<span class="asterisk">*</span><asp:Label ID="Label3" runat="server" Text="Salary"></asp:Label>
</td>
<td>
<asp:TextBox ID="salaryBox" runat="server" CssClass="box" MaxLength="8" ></asp:TextBox>
<asp:RequiredFieldValidator ID="salaryValidate" runat="server" ControlToValidate="salaryBox"
ErrorMessage="Salary is required!" Display="None" CssClass="error_msg" SetFocusOnError="true"
EnableClientScript="true"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="SalaryValidator" runat="server" ErrorMessage="Salary can contain only numeric values."
Display="None" ControlToValidate="salaryBox" ValidationExpression="^[0-9]*$"
CssClass="error_msg"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
<span class="asterisk">*</span><asp:Label ID="gender" runat="server" Text="Gender"></asp:Label>
</td>
<td>
<span>
<asp:RadioButton GroupName="gendergrp" ID="gendermale" runat="server" Text="Male"
Checked="true" /></span><span style="padding-left: 5px;">
<asp:RadioButton GroupName="gendergrp" ID="genderfemale" runat="server" Text="Female"
Checked="false" /></span>
</td>
</tr>
<tr>
<td>
<div style="float: right; margin-right: -70px;">
<asp:Button ID="Button1" runat="server" CssClass="btn" Text="Save" OnClick="Button1_Click" /></div>
</td>
<td>
<div style="float: left; margin-left: 70px;">
<asp:Button ID="CancelBtn" CausesValidation="false" runat="server" CssClass="btn"
Text="Cancel" OnClick="CancelBtn_Click" />
</div>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblError" runat="server" CssClass="error_msg"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2">
<asp:ValidationSummary ID="valSum" DisplayMode="BulletList" EnableClientScript="true"
HeaderText="Error!" runat="server" CssClass="error_msg" />
</td>
</tr>
</table>
<!--div for data display-->
<div class="data_display">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="EmployeeID" EmptyDataText="There are no data records to display."
GridLines="Horizontal" BackColor="#CCCCCC" BorderColor="White" Font-Bold="False"
Font-Names="Arial" Font-Size="Medium" ForeColor="#666666"
AllowPaging="True" PageSize="5" PagerSettings-Mode="Numeric"
PagerSettings-Position="Bottom"
onpageindexchanging="GridView1_PageIndexChanging"
>
<Columns>
<%-- <asp:TemplateField>
<ItemTemplate>
<asp:HiddenField ID="EmpID" runat="server" Value='<%# Eval("EmployeeID") %>' />
</ItemTemplate>
</asp:TemplateField>
--%> <asp:BoundField DataField="EmployeeID" HeaderText="Employee ID"
SortExpression="EmployeeID" Visible="true" ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="EmployeeName" HeaderText="Name" SortExpression="EmployeeName"
ItemStyle-Width="130px" ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" Width="130px" />
</asp:BoundField>
<asp:BoundField DataField="DateOfBirth" HeaderText="DoB" SortExpression="DateOfBirth"
DataFormatString="{0:dd-MM-yyyy}" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="Salary" HeaderText="Salary"
SortExpression="Salary">
<ItemStyle HorizontalAlign="Center" Width="90px" />
</asp:BoundField>
<asp:BoundField DataField="Gender" HeaderText="Gender" ItemStyle-Width="90px"
ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" Width="70px" />
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="EditBtn" runat="server" Text="Select" CausesValidation="false" OnClick="EditBtn_Click" />
<asp:Button ID="DelBtn" runat="server" Text="Delete" CausesValidation="false" OnClick="DelBtn_Click" OnClientClick="confirmDelete()" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#ffffff" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Gray" Font-Bold="false" ForeColor="White" />
<PagerStyle BackColor="Gray" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
<br />
<span style="font-family: Arial; font-size: small; color: Green; font-weight: bold;">
You are viewing page <%=GridView1.PageIndex + 1%> of <%=GridView1.PageCount%>
</span>
</div>
<div>
<asp:Label ID="lblMessage" runat="server"></asp:Label></div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
**code behind:**
#region GridView Functions
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[4].Text == "True")
{
e.Row.Cells[4].Text = "Male";
}
else
{
e.Row.Cells[4].Text = "Female";
}
}
}
#endregion
The gridview Gender column shows true/false instead of male/female.
Thanks!
You need a TemplateField for this. Assuming Male equates to True, this should work:
<asp:TemplateField HeaderText="Gender" SortExpression="Gender">
<ItemTemplate><%# (Boolean.Parse(Eval("Gender").ToString())) ? "Male" : "Female" %></ItemTemplate>
</asp:TemplateField>
I Have a listView and I want to create a button or link that when user click,goes to a page that have a formview and it's datasourse configured :
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:akhbarrConnectionString %>"
SelectCommand="SELECT [DarkhastId], [shakhs], [nam], [Idgharardad], [elat], [hamrah], [sabet], [karshenas], [tarikh] FROM [darkhastezam] WHERE ([DarkhastId] = #DarkhastId)">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="0" Name="DarkhastId"
QueryStringField="DarkhastId" Type="Decimal" />
</SelectParameters>
so I need a link in page 1 for paasing DarkhastId with query string to page 2.
I tried these one after another but not responsible:
<asp:HyperLinkField DataNavigateUrlFields="DarkhastId" DataNavigateUrlFormatString="showprofile.aspx?DarkhastId={0}" HeaderText="پاسخ دهی" Text="پاسخ دهی" />
protected void ListView1_ItemUpdated(object sender, ListViewUpdatedEventArgs e)
{
if (e.Exception == null && e.AffectedRows > 0)
{
string url="showprofile.aspx?DarkhastId="+e.OldValues["DarkhastId"];
Response.Redirect(url);
}
}
my listview codes:
<asp:ListView ID="ListView1" runat="server" DataKeyNames="DarkhastId"
DataSourceID="SqlDataSource1" GroupItemCount="2"
onitemupdated="ListView1_ItemUpdated">
<AlternatingItemTemplate>
<td runat="server" style="" >
<div id="printarea">
شناسه ی درخواست :
<asp:Label ID="DarkhastIdLabel" runat="server"
Text='<%# Eval("DarkhastId") %>' />
<br />
شخص :
<asp:Label ID="shakhsLabel" runat="server" Text='<%# Eval("shakhs") %>' />
<br />
نام و نام خانوادگی :
<asp:Label ID="namLabel" runat="server" Text='<%# Eval("nam") %>' />
<br />
شماره قرارداد :
<asp:Label ID="IdgharardadLabel" runat="server"
Text='<%# Eval("Idgharardad") %>' />
<br />
شرح درخواست :
<asp:Label ID="elatLabel" runat="server" Text='<%# Eval("elat") %>' />
<br />
شماره موبایل :
<asp:Label ID="hamrahLabel" runat="server" Text='<%# Eval("hamrah") %>' />
<br />
شماره تلفن ثابت :
<asp:Label ID="sabetLabel" runat="server" Text='<%# Eval("sabet") %>' />
<br />
وضعیت پیگیری :
<asp:Label ID="vaziatLabel" runat="server" Text='<%# Eval("vaziat") %>' />
<br />
کارشناس (های) اعزامی :
<asp:Label ID="karshenasLabel" runat="server" Text='<%# Eval("karshenas") %>' />
<br />
تاریخ ثبت درخواست :
<asp:Label ID="tarikhLabel" runat="server" Text='<%# Eval("tarikh") %>' />
<br />
</div>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="حذف درخواست" />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="ویرایش درخواست" />
<br />
<asp:HyperLinkField DataNavigateUrlFields="DarkhastId" DataNavigateUrlFormatString="showprofile.aspx?DarkhastId={0}" HeaderText="پاسخ دهی" Text="پاسخ دهی" />
<input id="btnprint" type="button" onclick="PrintDiv()" value="print" />
</td>
</AlternatingItemTemplate>
<EditItemTemplate>
<td runat="server" class="testak">
<table>
<tr>
<td>تاریخ ثبت درخواست : </td>
<td><asp:Label ID="tarikhTextBox" runat="server" Text='<%# Bind("tarikh") %>' /></td>
<td></td>
</tr>
<tr>
<td>شناسه درخواست : </td>
<td> <asp:Label ID="DarkhastIdLabel1" runat="server"
Text='<%# Eval("DarkhastId") %>' /></td>
<td></td>
</tr>
<tr>
<td> شخص : </td>
<td> <asp:TextBox ID="shakhsTextBox" runat="server" Text='<%# Bind("shakhs") %>' /></td>
<td></td>
</tr>
<tr>
<td>نام و نام خانوادگی :</td>
<td> <asp:TextBox ID="namTextBox" CssClass="field" Width="315px" runat="server" Text='<%# Bind("nam") %>' /></td>
<td></td>
</tr>
<tr>
<td>شماره قرارداد : </td>
<td><asp:TextBox CssClass="field" Width="315px" ID="IdgharardadTextBox" runat="server"
Text='<%# Bind("Idgharardad") %>' /></td>
<td></td>
</tr>
<tr>
<td>شرح درخواست : </td>
<td> <asp:TextBox CssClass="field" Height="194px" TextMode="MultiLine" Width="315px" ID="elatTextBox" runat="server" Text='<%# Bind("elat") %>' /></td>
<td></td>
</tr>
<tr>
<td>شماره موبایل : </td>
<td><asp:TextBox ID="hamrahTextBox" CssClass="field" Width="315px" runat="server" Text='<%# Bind("hamrah") %>' /></td>
<td></td>
</tr>
<tr>
<td>شماره تلفن ثابت : </td>
<td><asp:TextBox ID="sabetTextBox" CssClass="field" Width="315px" runat="server" Text='<%# Bind("sabet") %>' /></td>
<td></td>
</tr>
<tr>
<td>وضعیت پیگیری : </td>
<td><asp:TextBox ID="vaziatTextBox" runat="server" Text='<%# Bind("vaziat") %>' /></td>
<td></td>
</tr>
<tr>
<td> کارشناس (های) اعزامی : </td>
<td><asp:TextBox CssClass="field" Height="194px" TextMode="MultiLine" Width="315px" ID="karshenasTextBox" runat="server"
Text='<%# Bind("karshenas") %>' /></td>
<td></td>
</tr>
<tr>
<td> <asp:Button ID="UpdateButton" runat="server" CommandName="Update"
Text="به روز رسانی" /></td>
<td><asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="لغو ویرایش" /></td>
<td></td>
</tr>
</table>
</td>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>
اطلاعاتی برای نمایش موجود نیست.</td>
</tr>
</table>
</EmptyDataTemplate>
<EmptyItemTemplate>
<td runat="server" />
</EmptyItemTemplate>
<GroupTemplate>
<tr ID="itemPlaceholderContainer" runat="server">
<td ID="itemPlaceholder" runat="server">
</td>
</tr>
</GroupTemplate>
<InsertItemTemplate>
<td runat="server" style="">
شخص :
<asp:TextBox CssClass="Test" ID="shakhsTextBox" runat="server" Text='<%# Bind("shakhs") %>' />
<br />
نام و نام خانوادگی :
<asp:TextBox CssClass="Test" ID="namTextBox" runat="server" Text='<%# Bind("nam") %>' />
<br />
شماره قرارداد :
<asp:TextBox CssClass="Test" ID="IdgharardadTextBox" runat="server"
Text='<%# Bind("Idgharardad") %>' />
<br />
شرح درخواست :
<asp:TextBox CssClass="Test" ID="elatTextBox" runat="server" Text='<%# Bind("elat") %>' />
<br />
شماره موبایل :
<asp:TextBox CssClass="Test" ID="hamrahTextBox" runat="server" Text='<%# Bind("hamrah") %>' />
<br />
شماره تلفن ثابت :
<asp:TextBox CssClass="Test" ID="sabetTextBox" runat="server" Text='<%# Bind("sabet") %>' />
<br />
وضعیت پیگیری :
<asp:TextBox CssClass="Test" ID="vaziatTextBox" runat="server" Text='<%# Bind("vaziat") %>' />
<br />
کارشناس (های) اعزامی :
<asp:TextBox CssClass="Test" ID="karshenasTextBox" runat="server"
Text='<%# Bind("karshenas") %>' />
<br />
تاریخ ثبت درخواست :
<asp:TextBox CssClass="Test" ID="tarikhTextBox" runat="server" Text='<%# Bind("tarikh") %>' />
<br />
<asp:Button CssClass="Test" ID="InsertButton" runat="server" CommandName="Insert"
Text="ثبت درخواست" />
<br />
<asp:Button CssClass="Test" ID="CancelButton" runat="server" CommandName="Cancel"
Text="پاک کردن فرم" />
<br />
</td>
</InsertItemTemplate>
<ItemTemplate>
<td runat="server" style="">
شناسه درخواست :
<asp:Label CssClass="Test" ID="DarkhastIdLabel" runat="server"
Text='<%# Eval("DarkhastId") %>' />
<br />
شخص :
<asp:Label CssClass="Test" ID="shakhsLabel" runat="server" Text='<%# Eval("shakhs") %>' />
<br />
نام و نام خانوادگی :
<asp:Label CssClass="Test" ID="namLabel" runat="server" Text='<%# Eval("nam") %>' />
<br />
شماره قرارداد :
<asp:Label CssClass="Test" ID="IdgharardadLabel" runat="server"
Text='<%# Eval("Idgharardad") %>' />
<br />
شرح درخواست :
<asp:Label CssClass="Test" ID="elatLabel" runat="server" Text='<%# Eval("elat") %>' />
<br />
شماره موبایل :
<asp:Label CssClass="Test" ID="hamrahLabel" runat="server" Text='<%# Eval("hamrah") %>' />
<br />
شماره تلفن ثابت :
<asp:Label CssClass="Test" ID="sabetLabel" runat="server" Text='<%# Eval("sabet") %>' />
<br />
وضعیت پیگیری :
<asp:Label CssClass="Test" ID="vaziatLabel" runat="server" Text='<%# Eval("vaziat") %>' />
<br />
کارشناس (های) اعزامی :
<asp:Label CssClass="Test" ID="karshenasLabel" runat="server" Text='<%# Eval("karshenas") %>' />
<br />
تاریخ ثبت درخواست :
<asp:Label CssClass="Test" ID="tarikhLabel" runat="server" Text='<%# Eval("tarikh") %>' />
<br />
<asp:Button CssClass="Test" ID="DeleteButton" runat="server" CommandName="Delete"
Text="حذف درخواست" />
<br />
<asp:Button CssClass="Test" ID="EditButton" runat="server" CommandName="Edit" Text="ویرایش درخواست" />
<br />
</td>
</ItemTemplate>
<LayoutTemplate>
<table runat="server" class="testa" style=" ">
<tr runat="server" style="">
<td runat="server" >
<table ID="groupPlaceholderContainer" runat="server" border="0" >
<tr ID="groupPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
<asp:DataPager ID="DataPager1" runat="server" PageSize="12">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<td runat="server" style="">
شناسه درخواست :
<asp:Label CssClass="Test" ID="DarkhastIdLabel" runat="server"
Text='<%# Eval("DarkhastId") %>' />
<br />
شخص :
<asp:Label CssClass="Test" ID="shakhsLabel" runat="server" Text='<%# Eval("shakhs") %>' />
<br />
نام و نام خانوادکی :
<asp:Label CssClass="Test" ID="namLabel" runat="server" Text='<%# Eval("nam") %>' />
<br />
شماره قرارداد :
<asp:Label CssClass="Test" ID="IdgharardadLabel" runat="server"
Text='<%# Eval("Idgharardad") %>' />
<br />
شرح درخواست :
<asp:Label CssClass="Test" ID="elatLabel" runat="server" Text='<%# Eval("elat") %>' />
<br />
شماره موبایل :
<asp:Label CssClass="Test" ID="hamrahLabel" runat="server" Text='<%# Eval("hamrah") %>' />
<br />
شماره تلفن ثابت :
<asp:Label CssClass="Test" ID="sabetLabel" runat="server" Text='<%# Eval("sabet") %>' />
<br />
وضعیت پیگیری :
<asp:Label CssClass="Test" ID="vaziatLabel" runat="server" Text='<%# Eval("vaziat") %>' />
<br />
کارشناس (های) اعزامی :
<asp:Label CssClass="Test" ID="karshenasLabel" runat="server" Text='<%# Eval("karshenas") %>' />
<br />
تاریخ ثبت درخواست :
<asp:Label CssClass="Test" ID="tarikhLabel" runat="server" Text='<%# Eval("tarikh") %>' />
<br />
<asp:Button CssClass="Test" ID="DeleteButton" runat="server" CommandName="Delete"
Text="حذف درخواست" />
<br />
<asp:Button CssClass="Test" ID="EditButton" runat="server" CommandName="Edit" Text="ویرایش درخواست" />
<br />
</td>
</SelectedItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:akhbarrrConnectionString %>"
DeleteCommand="DELETE FROM [darkhastezam] WHERE [DarkhastId] = #DarkhastId"
InsertCommand="INSERT INTO [darkhastezam] ([shakhs], [nam], [Idgharardad], [elat], [hamrah], [sabet], [vaziat], [karshenas], [tarikh]) VALUES (#shakhs, #nam, #Idgharardad, #elat, #hamrah, #sabet, #vaziat, #karshenas, #tarikh)"
SelectCommand="SELECT * FROM [darkhastezam]"
UpdateCommand="UPDATE [darkhastezam] SET [shakhs] = #shakhs, [nam] = #nam, [Idgharardad] = #Idgharardad, [elat] = #elat, [hamrah] = #hamrah, [sabet] = #sabet, [vaziat] = #vaziat, [karshenas] = #karshenas, [tarikh] = #tarikh WHERE [DarkhastId] = #DarkhastId">
<DeleteParameters>
<asp:Parameter Name="DarkhastId" Type="Decimal" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="shakhs" Type="String" />
<asp:Parameter Name="nam" Type="String" />
<asp:Parameter Name="Idgharardad" Type="Decimal" />
<asp:Parameter Name="elat" Type="String" />
<asp:Parameter Name="hamrah" Type="String" />
<asp:Parameter Name="sabet" Type="String" />
<asp:Parameter Name="vaziat" Type="String" />
<asp:Parameter Name="karshenas" Type="String" />
<asp:Parameter Name="tarikh" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="shakhs" Type="String" />
<asp:Parameter Name="nam" Type="String" />
<asp:Parameter Name="Idgharardad" Type="Decimal" />
<asp:Parameter Name="elat" Type="String" />
<asp:Parameter Name="hamrah" Type="String" />
<asp:Parameter Name="sabet" Type="String" />
<asp:Parameter Name="vaziat" Type="String" />
<asp:Parameter Name="karshenas" Type="String" />
<asp:Parameter Name="tarikh" Type="String" />
<asp:Parameter Name="DarkhastId" Type="Decimal" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
you are doing right just get it on the page load of showprofile.aspx like this:
protected void Page_Load(object sender, EventArgs e)
{
string v = Request.QueryString["DarkhastId"];
if (v != null)
{
Response.Write("param is ");
Response.Write(v);
}
}
}
*Update: *
you need to access the DarkhastId from ListView Keys like this in the ListView1_ItemUpdated event:
protected void ListView1_ItemUpdated(object sender, ListViewUpdatedEventArgs e)
{
if ((sender as ListView) != null)
{
int id = Convert.ToInt32(ListView1.DataKeys[Index]["DarkhastId"]);
string url="showprofile.aspx?DarkhastId="+id
Response.Redirect(url);
}
}
here is reference answer:
http://forums.asp.net/t/1412741.aspx?Get+the+key+value+of+an+updated+ListView+item+in+the+ItemUpdated+event
you can see example here:
http://asp-net-example.blogspot.com/2009/01/aspnet-querystring-example-how-to-use.html
I have two tables in my database as following:
Employee Table: Username, Name, Job, DivisonCode
Division Table: DivisionCode, DivisionName
I am using ListView to show the information of the employee. Instead of showing the DivisionCode, I put a DropDownList that for showing the DivsionNames and of course I put this DropDownList inside the EditItemTemplate in the ListView. Everything works fine except editing the employee information. When I tried to change the division of the employee, I got the following error:
Cannot insert the value NULL into column 'DivisionCode', table
'psspdbTest.dbo.employee'; column does not allow nulls. UPDATE fails.
The statement has been terminated.
My Code in ASP.NET:
<asp:ListView ID="ListView1" runat="server" DataKeyNames="Username"
DataSourceID="SqlDataSource1" InsertItemPosition="LastItem" >
<AlternatingItemTemplate>
<tr style="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
</td>
<td>
<asp:Label ID="UsernameLabel" runat="server" Text='<%# Eval("Username") %>' />
</td>
<td>
<asp:Label ID="JobTitleLabel" runat="server" Text='<%# Eval("JobTitle") %>' />
</td>
<td>
<asp:Label ID="BadgeNoLabel" runat="server"
Text='<%# Eval("BadgeNo") %>' />
</td>
<td>
<asp:Label ID="EmpOrgTypeLabel" runat="server"
Text='<%# Eval("EmpOrgType") %>' />
</td>
<td>
<asp:Label ID="DivisionCodeLabel" runat="server"
Text='<%# Eval("DivisionCode") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update"
Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Cancel" />
</td>
<td>
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
</td>
<td>
<asp:Label ID="UsernameLabel1" runat="server" Text='<%# Eval("Username") %>' />
</td>
<td>
<asp:TextBox ID="JobTitleTextBox" runat="server"
Text='<%# Bind("JobTitle") %>' />
</td>
<td>
<asp:TextBox ID="BadgeNoTextBox" runat="server" Text='<%# Bind("BadgeNo") %>' />
</td>
<td>
<asp:TextBox ID="EmpOrgTypeTextBox" runat="server"
Text='<%# Bind("EmpOrgType") %>' />
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource1" DataTextField="DivisionName"
DataValueField="SapCode">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
DeleteCommand="DELETE FROM [Divisions] WHERE [SapCode] = #SapCode"
InsertCommand="INSERT INTO [Divisions] ([SapCode], [DivisionName]) VALUES (#SapCode, #DivisionName)"
SelectCommand="SELECT * FROM [Divisions]"
UpdateCommand="UPDATE [Divisions] SET [DivisionName] = #DivisionName WHERE [SapCode] = #SapCode">
<DeleteParameters>
<asp:Parameter Name="SapCode" Type="Double" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="SapCode" Type="Double" />
<asp:Parameter Name="DivisionName" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="DivisionName" Type="String" />
<asp:Parameter Name="SapCode" Type="Double" />
</UpdateParameters>
</asp:SqlDataSource>
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server"
style="">
<tr>
<td>
No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Clear" />
</td>
<td>
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
</td>
<td>
<asp:TextBox ID="UsernameTextBox" runat="server"
Text='<%# Bind("Username") %>' />
</td>
<td>
<asp:TextBox ID="JobTitleTextBox" runat="server"
Text='<%# Bind("JobTitle") %>' />
</td>
<td>
<asp:TextBox ID="BadgeNoTextBox" runat="server" Text='<%# Bind("BadgeNo") %>' />
</td>
<td>
<asp:TextBox ID="EmpOrgTypeTextBox" runat="server"
Text='<%# Bind("EmpOrgType") %>' />
</td>
<td>
<asp:TextBox ID="DivisionCodeTextBox" runat="server"
Text='<%# Bind("DivisionCode") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit"
Text="Edit" />
</td>
<td>
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
</td>
<td>
<asp:Label ID="UsernameLabel" runat="server" Text='<%# Eval("Username") %>' />
</td>
<td>
<asp:Label ID="JobTitleLabel" runat="server" Text='<%# Eval("JobTitle") %>' />
</td>
<td>
<asp:Label ID="BadgeNoLabel" runat="server" Text='<%# Eval("BadgeNo") %>' />
</td>
<td>
<asp:Label ID="EmpOrgTypeLabel" runat="server"
Text='<%# Eval("EmpOrgType") %>' />
</td>
<td>
<asp:Label ID="DivisionCodeLabel" runat="server"
Text='<%# Eval("DivisionCode") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table ID="itemPlaceholderContainer" runat="server" border="0"
style="">
<tr runat="server" style="">
<th runat="server">
</th>
<th runat="server">
Name</th>
<th runat="server">
Username</th>
<th runat="server">
JobTitle</th>
<th runat="server">
BadgeNo</th>
<th runat="server">
EmpOrgType</th>
<th runat="server">
DivisionCode</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server"
style="">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
</td>
<td>
<asp:Label ID="UsernameLabel" runat="server" Text='<%# Eval("Username") %>' />
</td>
<td>
<asp:Label ID="JobTitleLabel" runat="server" Text='<%# Eval("JobTitle") %>' />
</td>
<td>
<asp:Label ID="BadgeNoLabel" runat="server"
Text='<%# Eval("BadgeNo") %>' />
</td>
<td>
<asp:Label ID="EmpOrgTypeLabel" runat="server"
Text='<%# Eval("EmpOrgType") %>' />
</td>
<td>
<asp:Label ID="DivisionCodeLabel" runat="server"
Text='<%# Eval("DivisionCode") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
SelectCommand="SELECT dbo.employee.Name, dbo.employee.Username, dbo.employee.JobTitle, dbo.employee.BadgeNo, dbo.employee.EmpOrgType, dbo.employee.DivisionCode
FROM dbo.Divisions INNER JOIN
dbo.employee ON dbo.Divisions.SapCode = dbo.employee.DivisionCode"
DeleteCommand="DELETE FROM [employee] WHERE [Username] = #Username"
InsertCommand="INSERT INTO [employee] ([Name], [Username], [JobTitle], [BadgeNo], [EmpOrgType], [DivisionCode]) VALUES (#Name, #Username, #JobTitle, #BadgeNo, #EmpOrgType, #DivisionCode)"
UpdateCommand="UPDATE [employee] SET [Name] = #Name, [JobTitle] = #JobTitle, [BadgeNo] = #BadgeNo, [EmpOrgType] = #EmpOrgType, [DivisionCode] = #DivisionCode WHERE [Username] = #Username">
<DeleteParameters>
<asp:Parameter Name="Username" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Username" Type="String" />
<asp:Parameter Name="JobTitle" Type="String" />
<asp:Parameter Name="BadgeNo" Type="Double" />
<asp:Parameter Name="EmpOrgType" Type="Double" />
<asp:Parameter Name="DivisionCode" Type="Double" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="JobTitle" Type="String" />
<asp:Parameter Name="BadgeNo" Type="Double" />
<asp:Parameter Name="EmpOrgType" Type="Double" />
<asp:Parameter Name="DivisionCode" Type="Double" />
<asp:Parameter Name="Username" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
So how to solve this problem?
Add this to your DropDownList SelectedValue='<%# Bind("DivisionCode") %>'
and remove AutoPostBack="true"