Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / May 2008

Tip: Looking for answers? Try searching our database.

trying to loop through rows in gridview.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul - 21 May 2008 18:36 GMT
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.
Signature

Paul G
Software engineer.

Mark Rae [MVP] - 21 May 2008 18:49 GMT
> 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 ?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.