trying to loop through rows in gridview.

Discussion in 'ASP .Net' started by Paul, May 21, 2008.

  1. Paul

    Paul Guest

    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.
     
    Paul, May 21, 2008
    #1
    1. Advertising

  2. Paul

    Paul Guest

    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" <> wrote in message
    > news:...
    >
    > > 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
    >
    >
     
    Paul, May 21, 2008
    #2
    1. Advertising

  3. Paul

    Paul Guest

    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" <> wrote in message
    > news:...
    >
    > [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
    >
    >
     
    Paul, May 21, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fraggle

    loop through rows in a table

    Fraggle, Nov 19, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    16,707
    Pat Alessi
    Nov 24, 2003
  2. VijayRama
    Replies:
    2
    Views:
    2,398
    Gregory A. Beamer
    Oct 12, 2009
  3. donnet

    Use of "Repeater" control to loop through data rows

    donnet, Jan 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    849
    JDP@Work
    Jan 17, 2005
  4. addi
    Replies:
    0
    Views:
    293
  5. Isaac Won
    Replies:
    9
    Views:
    453
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page