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 BegRank #284 · 8.8K reputationPosted Apr 14, 2021, 12:43 PM EDT
Salman BegRank #284 · 8.8K reputationPosted Apr 14, 2021, 9:56 AM EDT
Valerie MeunierRank #1,527 · 1K reputationPosted Apr 14, 2021, 10:40 AM EDT
Valerie MeunierRank #1,527 · 1K reputationPosted Apr 14, 2021, 2:20 PM EDT
Valerie MeunierRank #1,527 · 1K reputationPosted Apr 15, 2021, 6:43 AM EDT