Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Cells numbers problem on OnItemCommand

Reply
Thread Tools

Cells numbers problem on OnItemCommand

 
 
ree32
Guest
Posts: n/a
 
      09-07-2004
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?
 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      09-07-2004
/// <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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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?



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with OnItemCommand event and Loadtemplate =?Utf-8?B?QW50b25pbyBDYXJwZW50aWVyaQ==?= ASP .Net 5 04-16-2008 03:25 AM
convert yyyymmdd text cells into date cells =?Utf-8?B?ZF9jYW1wZWxvQGhvdG1haWwuY29t?= Microsoft Certification 2 11-22-2006 04:52 PM
Writing to Cells in the Detailsview Insertmode makes cells uneditable. SixStringSlaya@gmail.com ASP .Net 0 02-28-2006 10:23 PM
datagrid OnItemCommand handler not executing Rick White ASP .Net 1 01-13-2004 05:41 AM
Cells[].Text or Cells[].Controls[0] Joel Finkel ASP .Net Datagrid Control 0 09-01-2003 04:42 PM



Advertisments