Valerie Meunier

Valerie Meunier

  • NA
  • 693
  • 82.8k

filling dropdownlist doesn't work

Apr 14 2021 1:42 PM
Hi,
 
I try to fill via code-behind a dropdownlist located in a gridview.
 
But it remains empty.
 
Thanks for help.
  1. protected void GridView1_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
  2. {  
  3. if ((e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit)  
  4. {  
  5. if (e.Row.RowType == DataControlRowType.DataRow)  
  6. {  
  7. DropDownList dd1;  
  8. ListItem z;  
  9. string m;  
  10. dd1 = (DropDownList)e.Row.FindControl("matdd");  
  11. using (SqlConnection mConnection = new SqlConnection(param.ConnectionString))  
  12. {  
  13. mConnection.Open();  
  14. sql = "select name from mat order by name";  
  15. comd = new SqlCommand(sql, mConnection);  
  16. dtreader = comd.ExecuteReader();  
  17. if (dtreader.HasRows)  
  18. {  
  19. while (dtreader.Read())  
  20. {  
  21. m = dtreader.GetString(0);  
  22. z = new ListItem(m);  
  23. dd1.Items.Add(z);  
  24. }  
  25. }  
  26. dtreader.Close();  
  27. mConnection.Close();  
  28. }  
  29. dd1.ClearSelection();  
  30. }  
  31. }  
  32. }  

Answers (5)