Cells numbers problem on OnItemCommand

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Cells numbers problem on OnItemCommand

    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 Guest

  2. Similar Questions and Discussions

    1. datagrid onitemcommand not firing
      Here's my problem. I have a Button. On clicking, it binds data to datagrid grid1 grid1 has a Column of LinkButton OnItemCommand of this grid1...
    2. DataGrid OnItemCommand
      I assume that you are re-creating this, and adding the handler, on every page load (postback or not). You have to do that with dynamically created...
    3. How To get a column name when OnItemCommand is fired
      Hello, I have a OnItemCommand event in the datagrid that could select all the row in it by a linkbutton, the problem is that there are 7...
    4. ASP & Excel (problem reading cells)
      Hello, I'm having a bit of a problem with ASP and Excel. A client has developed his own program, which calculates alot of financial stuff, in...
    5. Cells[].Text or Cells[].Controls[0]
      Folks, The following code illustrates two methods of obtaining the contents of a DataGrid Item. The function has been bound to the ItemCommand of...
  3. #2

    Default Re: Cells numbers problem on OnItemCommand

    /// <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" <ree32@hotmail.com> wrote in message
    news:7606ccc8.0409061928.2d9d024e@posting.google.c om...
    > 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 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139