<asp:GridView ID="gvPerson" ShowFooter="true" RowStyle-VerticalAlign="top" DataKeyNames="id" runat="server" AutoGenerateColumns="False" OnRowEditing="gvPerson_RowEditing" OnRowDataBound="gvPerson_RowDataBound" OnRowUpdating="gvPerson_RowUpdating"> <Columns> <asp:TemplateField HeaderText="Country"> <ItemTemplate><%#Eval("PersonCountry") %></ItemTemplate> <EditItemTemplate> <asp:DropDownList ID="NewddlCountry" AutoPostBack="true" OnSelectedIndexChanged="NewddlCountry_SelectedIndexChanged" runat="server"></asp:DropDownList> <asp:RequiredFieldValidator ID="RequiredFieldValidator3" ValidationGroup="v2" runat="server" ControlToValidate="NewddlCountry" ErrorMessage="Select Country"></asp:RequiredFieldValidator> </EditItemTemplate> <FooterTemplate> <asp:Button ID="btnAddNew" OnClick="btnAddNew_Click" runat="server" Text="AddNew" /> </FooterTemplate> </asp:TemplateField> </asp:GridView>
protected void gvPerson_RowDataBound(object sender, GridViewRowEventArgs e) { DataRowView drv = e.Row.DataItem as DataRowView; if (e.Row.RowType == DataControlRowType.DataRow) { if ((e.Row.RowState & DataControlRowState.Edit) > 0) { DropDownList NewddlCountry = (DropDownList)e.Row.FindControl("NewddlCountry"); DataSet tempCountries = BAL.GetCountries(); NewddlCountry.DataSource = tempCountries; NewddlCountry.DataTextField = "CountryName"; NewddlCountry.DataValueField = "CountryCode"; NewddlCountry.DataBind(); for (int i = 0; i < NewddlCountry.Items.Count; i++) { if (NewddlCountry.Items.Text.Trim().CompareTo(SelectedCounty.Trim()) == 0) { NewddlCountry.SelectedIndex = i; break; } } }
Join Hands Change lives Thanks & Regards Straight Edge Society
string value = (GridView1.Rows[Row_Index].FindControl("TextBox_Id") as TextBox).Text;
Sourabh07
Login to post response