Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > trying to loop through rows in gridview.

Reply
Thread Tools

trying to loop through rows in gridview.

 
 
Paul
Guest
Posts: n/a
 
      05-21-2008
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.
--
Paul G
Software engineer.
 
Reply With Quote
 
 
 
 
Paul
Guest
Posts: n/a
 
      05-21-2008
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 [MVP]" wrote:

> "Paul" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
> > 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...
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net
>
>

 
Reply With Quote
 
 
 
 
Paul
Guest
Posts: n/a
 
      05-21-2008
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 [MVP]" wrote:

> "Paul" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
> [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 ?
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Re: How to loop through a list while inside the loop, the list size may be decreased? Roedy Green Java 3 09-13-2008 01:51 AM
Use of "Repeater" control to loop through data rows donnet ASP .Net Web Controls 2 01-17-2005 07:38 PM
help: loop within a loop -how to display data in 3 columns by 4 rows format addi ASP General 0 12-31-2003 04:31 AM
loop through rows in a table Fraggle ASP .Net 3 11-24-2003 04:23 PM



Advertisments