Hi I have a gridview that has 1 row of data. I am trying to set the values
of dropdown boxes for each data row based on the data I have binded to the
grid but for some reason when I use the following below the rows are 0 so the
foreach is skipped.
gridview_RowDataBound()
{
foreach (GridViewRow dr in gridview.Rows)
}
Thanks.
> Hi I have a gridview that has 1 row of data. I am trying to set the
> values
[quoted text clipped - 7 lines]
> }
> Thanks.
The RowDataBound event occurs when each row *individually* is added to the
GridView allowing you to manipulate the row's data and controls in
isolation.
E.g. if you have a DropDownList in the first cell of the GridView, you would
do something like:
DropDownList MyDDL = (DropDownList)e.Row.Cells[0].FindControl("MyDDL");
Then you set the properties of the MyDDL variable as required...

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Paul - 21 May 2008 19:09 GMT
Thanks for the information! that seemed to work for 1 row setting
gridviewrowindex to 0. Is there an easy way to get the grid row
numberwithin the RowDataBound method as I need to set the index of the
listdisc to the gridview row number. This is inside the RowDataBound method.
DropDownList ddlcat = e.Row.Cells [1].FindControl("drdwnlistCategories") as
DropDownList;
ddlcat.SelectedValue = listdisc[gridviewrowindex].Description;

Signature
Paul G
Software engineer.
> > Hi I have a gridview that has 1 row of data. I am trying to set the
> > values
[quoted text clipped - 18 lines]
>
> Then you set the properties of the MyDDL variable as required...
Mark Rae [MVP] - 21 May 2008 19:22 GMT
[top-posting corrected]
>> The RowDataBound event occurs when each row *individually* is added to
>> the
[quoted text clipped - 19 lines]
> DropDownList;
> ddlcat.SelectedValue = listdisc[gridviewrowindex].Description;
What is listdisc[gridviewrowindex].Description ?

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Paul - 21 May 2008 19:36 GMT
Thanks for the response. I got it working, just set a manual counter.
listdisc[gridviewrowindex].Description is just a generic list containing data
where the description is what I need to set the dropdown selected value to
for each row.

Signature
Paul G
Software engineer.
> [top-posting corrected]
>
[quoted text clipped - 23 lines]
>
> What is listdisc[gridviewrowindex].Description ?