Cells numbers problem on OnItemCommand

Discussion in 'ASP .Net Datagrid Control' started by ree32, Sep 7, 2004.

  1. ree32

    ree32 Guest

    I am using a a datagrid to display results from a dataset.

    I have a button on each row of the grid, so when the user clicks on
    it, it displays more information from the the dataset which is not
    initially shown in the datagrid.

    But I have a problem as I don't know how to access the "hidden" column
    data using the column names. I have seen where the numbers of cells
    are used ..
    i.e .. e.Item.Cells(2).Text
    Is the number refering to the dataset or column layout on the datagrid
    itself?

    But I don't want use cell numbers as if I add another column in the
    database, wouldn't all the numbering of cells be thrown off?

    In datalists you can use e.Item.DataItem("ColumnName")
    is there any equivalent for Datagrids ?

    Or should I just stick to datalists?

    Or do I have this feeling I have to include all columns I want to use
    on the aspx page and then somehow make some columns hidden?
     
    ree32, Sep 7, 2004
    #1
    1. Advertising

  2. /// <summary>
    /// Returns DataGrid cell with given name in given datagrid item
    (row).
    /// </summary>
    /// <param name="item">DataGridItem - a row to search.</param>
    /// <param name="name">The name of the colimn to find.</param>
    /// <returns></returns>
    static public System.Web.UI.WebControls.TableCell CellByName
    (System.Web.UI.WebControls.DataGridItem item, string name)
    {
    try
    {
    System.Web.UI.WebControls.DataGrid grid = item.Parent.Parent
    as System.Web.UI.WebControls.DataGrid;
    for (int col = 0; col < item.Cells.Count; col++)
    if (grid.Columns[col].HeaderText == name)
    return item.Cells[col];
    }
    catch // ignore all exceptions
    {
    }

    // not found
    return null;
    }

    --
    Eliyahu

    "ree32" <> wrote in message
    news:...
    > I am using a a datagrid to display results from a dataset.
    >
    > I have a button on each row of the grid, so when the user clicks on
    > it, it displays more information from the the dataset which is not
    > initially shown in the datagrid.
    >
    > But I have a problem as I don't know how to access the "hidden" column
    > data using the column names. I have seen where the numbers of cells
    > are used ..
    > i.e .. e.Item.Cells(2).Text
    > Is the number refering to the dataset or column layout on the datagrid
    > itself?
    >
    > But I don't want use cell numbers as if I add another column in the
    > database, wouldn't all the numbering of cells be thrown off?
    >
    > In datalists you can use e.Item.DataItem("ColumnName")
    > is there any equivalent for Datagrids ?
    >
    > Or should I just stick to datalists?
    >
    > Or do I have this feeling I have to include all columns I want to use
    > on the aspx page and then somehow make some columns hidden?
     
    Eliyahu Goldin, Sep 7, 2004
    #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. Rick White
    Replies:
    1
    Views:
    1,603
    Natty Gur
    Jan 13, 2004
  2. Jim Heavey

    onItemCommand

    Jim Heavey, Feb 26, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    469
    Jim Heavey
    Feb 26, 2004
  3. =?Utf-8?B?QW50b25pbyBDYXJwZW50aWVyaQ==?=

    Problem with OnItemCommand event and Loadtemplate

    =?Utf-8?B?QW50b25pbyBDYXJwZW50aWVyaQ==?=, Sep 26, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    941
    leakingimplants
    Apr 16, 2008
  4. Replies:
    0
    Views:
    532
  5. 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
Loading...

Share This Page