How to programmatically retrieve all rows and cells in Gridview

Discussion in 'ASP .Net' started by JB, Jun 15, 2010.

  1. JB

    JB Guest

    Hello Community

    I have a Gridview.

    The Gridview already uses the SelectedRow command to allowusers to
    select each row and cell in the Gridview. Therefore the user can select any
    row that they want.

    The problem is that I need to write code that will do these things in the
    order of:

    1-Go to the first row in the Gridview
    2-Retrieve the value from each cell
    3-Store the value of each cell value in a variable

    This fails:

    for (int i = 1; i < gridview.Rows.Count; i++)

    {
    vlName = gview.Rows.Cells[1].Text;
    vfname = gview.Rows.Cells[2].Text;
    }

    The above fails because unless a row is first selected in the Gridview, it
    doesn't recognize a row in the Gridview.

    If it is possible, what is the code to retrieve each row and its cells from
    a Gridview programmatically without first selecting a row in the Gridview?

    Thanks
    Jeff
    --
    JB
     
    JB, Jun 15, 2010
    #1
    1. Advertising

  2. JB

    Mr. Arnold Guest

    JB wrote:
    > Hello Community
    >
    > I have a Gridview.
    >
    > The Gridview already uses the SelectedRow command to allowusers to
    > select each row and cell in the Gridview. Therefore the user can select any
    > row that they want.
    >
    > The problem is that I need to write code that will do these things in the
    > order of:
    >
    > 1-Go to the first row in the Gridview
    > 2-Retrieve the value from each cell
    > 3-Store the value of each cell value in a variable
    >
    > This fails:
    >
    > for (int i = 1; i < gridview.Rows.Count; i++)
    >
    > {
    > vlName = gview.Rows.Cells[1].Text;
    > vfname = gview.Rows.Cells[2].Text;
    > }
    >
    > The above fails because unless a row is first selected in the Gridview, it
    > doesn't recognize a row in the Gridview.
    >
    > If it is possible, what is the code to retrieve each row and its cells from
    > a Gridview programmatically without first selecting a row in the Gridview?
    >
    > Thanks
    > Jeff



    It's in VB, but you should be able to figure it out using a foreach in
    C#. It's the same thing in VB or C#.

    http://forums.asp.net/t/1219338.aspx

    But like the person has replied, you can only access the rows in the
    grid that have been rendered on the page.
     
    Mr. Arnold, Jun 15, 2010
    #2
    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. Replies:
    0
    Views:
    532
  2. S_K
    Replies:
    1
    Views:
    3,651
    Yankee Imperialist Dog
    Jun 5, 2008
  3. VijayRama
    Replies:
    2
    Views:
    2,333
    Gregory A. Beamer
    Oct 12, 2009
  4. Joel Finkel

    Cells[].Text or Cells[].Controls[0]

    Joel Finkel, Sep 1, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    313
    Joel Finkel
    Sep 1, 2003
  5. Matt Adamson

    Adding rows programmatically to GridView

    Matt Adamson, Mar 15, 2007, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    1,544
    Teemu Keiski
    Apr 9, 2007
Loading...

Share This Page