Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. <asp:TemplateField HeaderText="Country" HeaderStyle-HorizontalAlign="Left">
  2. <EditItemTemplate>
  3. <asp:DropDownList ID="DdlCountry" runat="server" DataTextField="Country" DataValueField="Sno">
  4. </asp:DropDownList>
  5. </EditItemTemplate>
  6. </asp:TemplateField>
  7.  
  8. int index = e.NewEditIndex;
  9. DropDownList DdlCountry = GridView1.Rows[index].FindControl("DdlCountry") as DropDownList;
  10.  
  11. int index = e.NewEditIndex;
  12. DataBindGridView(); // this is a method which assigns the DataSource and calls GridView1.DataBind()
  13. DropDownList DdlCountry = GridView1.Rows[index].FindControl("DdlCountry") as DropDownList;
  14.  
  15. protected void gridView1_RowDataBound(object sender, GridViewEditEventArgs e)
  16. {
  17. if (e.Row.RowType == DataControlRowType.DataRow)
  18. {
  19. if ((e.Row.RowState & DataControlRowState.Edit) > 0)
  20. {
  21. DropDownList DdlCountry = (DropDownList)e.Row.FindControl("DdlCountry");
  22. // bind DropDown manually
  23. DdlCountry.DataSource = GetCountryDataSource();
  24. DdlCountry.DataTextField = "country_name";
  25. DdlCountry.DataValueField = "country_id";
  26. DdlCountry.DataBind();
  27.  
  28. DataRowView dr = e.Row.DataItem as DataRowView;
  29. Ddlcountry.SelectedValue = value; // you can use e.Row.DataItem to get the value
  30. }
  31. }
  32. }
  33.  
  34. var DdlCountry = GridView1.Rows[GridView1.EditIndex].FindControl("DdlCountry") as DropDownList;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement