Hi I have a generic list of data
list <type> listcategory;
listcategory = new list <type>;
I also have a dropdown box that I have put into a template column of a
gridview.
I was able to populate the dropdown box ok when it was outside of the gridview
for (int i = 0; i <= listcategory.Count - 1; i++)
{
ddl.Items.Add(listcategory[i].Description);
}
Now that the control is in the gridview, ddl is not recognized.
I tried the following event but it does not seem to be reaching it.
protected void gridview_RowDataBound(object sender, DataGridItemEventArgs e)
{
;
}
I also tried the template edit from the gridview properties but could not
see how to bind the dropdown box to the items listcategory[i].Description.
Thanks.

Signature
Paul G
Software engineer.
Lee Thorpe - 20 May 2008 22:33 GMT
Paul
You need to use FindControl within your RowDataBound event-handler, i.e.
protected void gridview_RowDataBound(object sender, DataGridItemEventArgs e)
{
DropDownList ddl = e.Row.Cells[columnIndex].FindControl("ddl") as
DropDownList;
if (ddl != null)
{
// Databind, or populate ListItems in a loop.
}
}
> Hi I have a generic list of data
> list <type> listcategory;
[quoted text clipped - 20 lines]
> see how to bind the dropdown box to the items listcategory[i].Description.
> Thanks.
Lee Thorpe - 20 May 2008 22:34 GMT
Paul
You need to use FindControl within your RowDataBound event-handler, i.e.
protected void gridview_RowDataBound(object sender, DataGridItemEventArgs e)
{
DropDownList ddl = e.Row.Cells[columnIndex].FindControl("ddl") as
DropDownList;
if(ddl != null)
{
// Databind, or populate ListItems in a loop.
}
}
> Hi I have a generic list of data
> list <type> listcategory;
[quoted text clipped - 20 lines]
> see how to bind the dropdown box to the items listcategory[i].Description.
> Thanks.
Paul - 20 May 2008 23:08 GMT
thanks that worked!. Just had an additional question, I need the grid to
have 2 dropldown boxes but want the other fields to be two empty text box
columns for data entry, and a checkbox column for bool entry as well as a
final row count column,(just displays the row count). I had to bind the grid
to results of a dataset just to get the grid to show up so it currently has
extra undesired data from this dataset. Should I just create an empty
dataset and bind it to so a single row with two dropdowns and the other
fields discribed above show up?
Also I noticed there is no way to add a new row within the control, so
guessing this might have to be done outside the control.
Paul G
Software engineer.
> Paul
>
[quoted text clipped - 35 lines]
> > see how to bind the dropdown box to the items listcategory[i].Description.
> > Thanks.