Hi,
I try to fill via code-behind a dropdownlist located in a gridview.
But it remains empty.
Thanks for help.
- protected void GridView1_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
- {
- if ((e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- DropDownList dd1;
- ListItem z;
- string m;
- dd1 = (DropDownList)e.Row.FindControl("matdd");
- using (SqlConnection mConnection = new SqlConnection(param.ConnectionString))
- {
- mConnection.Open();
- sql = "select name from mat order by name";
- comd = new SqlCommand(sql, mConnection);
- dtreader = comd.ExecuteReader();
- if (dtreader.HasRows)
- {
- while (dtreader.Read())
- {
- m = dtreader.GetString(0);
- z = new ListItem(m);
- dd1.Items.Add(z);
- }
- }
- dtreader.Close();
- mConnection.Close();
- }
- dd1.ClearSelection();
- }
- }
- }
Salman BegPosted Apr 14, 2021, 4:43 PM
Valerie MeunierPosted Apr 15, 2021, 10:43 AM
Valerie MeunierPosted Apr 14, 2021, 6:20 PM
Valerie MeunierPosted Apr 14, 2021, 2:40 PM
Salman BegPosted Apr 14, 2021, 1:56 PM