Hi folks,
Consider the following code:
protected void gridView_RowDat aBound(object sender,
GridViewRowEven tArgs e)
{
GridViewRow row = e.Row;
if (row.RowType != DataControlRowT ype.DataRow)
return;
if (this.gridView. EditIndex != e.Row.RowIndex)
return;
if(someConditio nsApply)
{
DropDownList ddl = new DropDownList();
ddl.ID = "cbOtherAttribs " + row.RowIndex;
for (Int32 i = 0; i < 5; i++)
ddl.Items.Add(n ew ListItem(i.ToSt ring(), "0", true));
row.Cells[3].Controls.Add(d dl);
}
}
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_RowUpd ating(object sender,
GridViewUpdateE ventArgs e)
{
GridViewRow row = this.gridView.R ows[e.RowIndex];
Control c = row.Cells[3].FindControl("c bOtherAttribs" +
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_RowDat aBound(object sender,
GridViewRowEven tArgs e)
{
GridViewRow row = e.Row;
if (row.RowType != DataControlRowT ype.DataRow)
return;
if (this.gridView. EditIndex != e.Row.RowIndex)
return;
if(someConditio nsApply)
{
DropDownList ddl = new DropDownList();
ddl.ID = "cbOtherAttribs " + row.RowIndex;
for (Int32 i = 0; i < 5; i++)
ddl.Items.Add(n ew ListItem(i.ToSt ring(), "0", true));
row.Cells[3].Controls.Add(d dl);
}
}
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_RowUpd ating(object sender,
GridViewUpdateE ventArgs e)
{
GridViewRow row = this.gridView.R ows[e.RowIndex];
Control c = row.Cells[3].FindControl("c bOtherAttribs" +
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.
Comment