A
ata
Hi folks,
Consider the following code:
protected void gridView_RowDataBound(object sender,
GridViewRowEventArgs e)
{
GridViewRow row = e.Row;
if (row.RowType != DataControlRowType.DataRow)
return;
if (this.gridView.EditIndex != e.Row.RowIndex)
return;
if(someConditionsApply)
{
DropDownList ddl = new DropDownList();
ddl.ID = "cbOtherAttribs" + row.RowIndex;
for (Int32 i = 0; i < 5; i++)
ddl.Items.Add(new ListItem(i.ToString(), "0", true));
row.Cells[3].Controls.Add(ddl);
}
}
This way, I've dynamically added a DropDownList (DDL) control to the
GridView.
However, I need to get the value selected in the DDL when the row is
updating
and add it to the e.NewValues collection:
protected void gridView_RowUpdating(object sender,
GridViewUpdateEventArgs e)
{
GridViewRow row = this.gridView.Rows[e.RowIndex];
Control c = row.Cells[3].FindControl("cbOtherAttribs" +
row.RowIndex);
}
However, I've just noticed that the DDL Control I'm trying to retrieve
here is always null! The Cells collection only contains those controls
that's been added to the gridview declaratively.
Would you please let me know what's going on and how I'm supposed to
solve this?
Thanks.
Consider the following code:
protected void gridView_RowDataBound(object sender,
GridViewRowEventArgs e)
{
GridViewRow row = e.Row;
if (row.RowType != DataControlRowType.DataRow)
return;
if (this.gridView.EditIndex != e.Row.RowIndex)
return;
if(someConditionsApply)
{
DropDownList ddl = new DropDownList();
ddl.ID = "cbOtherAttribs" + row.RowIndex;
for (Int32 i = 0; i < 5; i++)
ddl.Items.Add(new ListItem(i.ToString(), "0", true));
row.Cells[3].Controls.Add(ddl);
}
}
This way, I've dynamically added a DropDownList (DDL) control to the
GridView.
However, I need to get the value selected in the DDL when the row is
updating
and add it to the e.NewValues collection:
protected void gridView_RowUpdating(object sender,
GridViewUpdateEventArgs e)
{
GridViewRow row = this.gridView.Rows[e.RowIndex];
Control c = row.Cells[3].FindControl("cbOtherAttribs" +
row.RowIndex);
}
However, I've just noticed that the DDL Control I'm trying to retrieve
here is always null! The Cells collection only contains those controls
that's been added to the gridview declaratively.
Would you please let me know what's going on and how I'm supposed to
solve this?
Thanks.