Re: Accessing the text in a cell of a gridview control

Discussion in 'ASP .Net' started by mark4asp, Jan 18, 2007.

  1. mark4asp

    mark4asp Guest

    On Wed, 17 Jan 2007 08:26:00 -0800, Randy
    <> wrote:

    >Hi,
    >In the old datagrid control in VS2003 the text in a cell could be accessed
    >by using the following sysntax:
    >e.Item.Cells(1).Text
    >
    >What is the Corresponding code to access the text in a cell of a new
    >gridview control?
    >
    >Thanks for any help


    You can access the items in the grid via the OnRowDataBound event
    with:

    e.Row.Cells[0].Text

    (for intance - for data in the first column)

    You can iterate through the row with something like

    if (e.Row.RowType == DataControlRowType.Header)
    {
    foreach (TableCell tc in e.Row.Cells)
    {
    tc.Text = tc.Text + ....
    }
    }

    (for intance for the column headers)

    If your GridView has DataKeyNames set equal the the key of the
    DataView which populates the Grid then the record key on a particular
    row (DataKey) will be:

    gvManagers.DataKeys[e.Row.DataItemIndex].Value

    (for instance for a GridView called gvManagers)
     
    mark4asp, Jan 18, 2007
    #1
    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. =?Utf-8?B?QmFzcyBQcm8=?=

    Accessing textbox control in a table cell

    =?Utf-8?B?QmFzcyBQcm8=?=, May 18, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    4,187
    =?Utf-8?B?QmFzcyBQcm8=?=
    May 19, 2005
  2. news.rcn.com
    Replies:
    1
    Views:
    9,741
    Chris Smith
    Jul 12, 2004
  3. James Irvine
    Replies:
    0
    Views:
    444
    James Irvine
    Jan 17, 2007
  4. LamSoft
    Replies:
    5
    Views:
    430
    LamSoft
    Jun 14, 2007
  5. S_K
    Replies:
    1
    Views:
    3,668
    Yankee Imperialist Dog
    Jun 5, 2008
Loading...

Share This Page