Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <asp:TemplateField HeaderText="Country" HeaderStyle-HorizontalAlign="Left">
- <EditItemTemplate>
- <asp:DropDownList ID="DdlCountry" runat="server" DataTextField="Country" DataValueField="Sno">
- </asp:DropDownList>
- </EditItemTemplate>
- </asp:TemplateField>
- int index = e.NewEditIndex;
- DropDownList DdlCountry = GridView1.Rows[index].FindControl("DdlCountry") as DropDownList;
- int index = e.NewEditIndex;
- DataBindGridView(); // this is a method which assigns the DataSource and calls GridView1.DataBind()
- DropDownList DdlCountry = GridView1.Rows[index].FindControl("DdlCountry") as DropDownList;
- protected void gridView1_RowDataBound(object sender, GridViewEditEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- if ((e.Row.RowState & DataControlRowState.Edit) > 0)
- {
- DropDownList DdlCountry = (DropDownList)e.Row.FindControl("DdlCountry");
- // bind DropDown manually
- DdlCountry.DataSource = GetCountryDataSource();
- DdlCountry.DataTextField = "country_name";
- DdlCountry.DataValueField = "country_id";
- DdlCountry.DataBind();
- DataRowView dr = e.Row.DataItem as DataRowView;
- Ddlcountry.SelectedValue = value; // you can use e.Row.DataItem to get the value
- }
- }
- }
- var DdlCountry = GridView1.Rows[GridView1.EditIndex].FindControl("DdlCountry") as DropDownList;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement