trying to loop through rows in gridview.

P

Paul

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.
 
P

Paul

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;
--
Paul G
Software engineer.


Mark Rae said:
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 bound 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.

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...
 
P

Paul

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.
--
Paul G
Software engineer.


Mark Rae said:
[top-posting corrected]
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...

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;

What is listdisc[gridviewrowindex].Description ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top