Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > URGENT question about binding collection to a datagrid onitemdatabound

Reply
Thread Tools

URGENT question about binding collection to a datagrid onitemdatabound

 
 
ITnerd
Guest
Posts: n/a
 
      10-31-2003
The following code works to hide specific columns before they are bound to a
datagrid that has "autogeneratecolumns=true"
enabled. My question is: is there any way to do the same from a bindable
user defined collection? I have a "message" class that I don't want to have
to
munge into a DataTable to get the desired effect.

public void Item_Bound(Object sender, DataGridItemEventArgs e)
{

DataTable dt = MyDataGrid.DataSource as DataTable;
DataColumnCollection dc = dt.Columns;
e.Item.Cells[dc.IndexOf(dc["MessageText"])].Visible = false;

}

Thanks in advance.



 
Reply With Quote
 
 
 
 
Giorgio Parmeggiani
Guest
Posts: n/a
 
      11-02-2003
Hi

I think that you can use this code, for any datasource, to hide your column:

public void Item_Bound(Object sender, DataGridItemEventArgs e)
{
foreach(TableCell cell in e.Item.Cells)
{
if(cell.Text == "MessageText") cell.Visible = false;
}
}

Giorgio

"ITnerd" <> ha scritto nel messaggio
news:i6GdnfgDYMWKVDyiRVn-...
> The following code works to hide specific columns before they are bound to

a
> datagrid that has "autogeneratecolumns=true"
> enabled. My question is: is there any way to do the same from a bindable
> user defined collection? I have a "message" class that I don't want to

have
> to
> munge into a DataTable to get the desired effect.
>
> public void Item_Bound(Object sender, DataGridItemEventArgs e)
> {
>
> DataTable dt = MyDataGrid.DataSource as DataTable;
> DataColumnCollection dc = dt.Columns;
> e.Item.Cells[dc.IndexOf(dc["MessageText"])].Visible = false;
>
> }
>
> Thanks in advance.
>
>
>



 
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
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen ASP .Net 1 05-18-2007 09:24 AM
ht get column in DataRowItem of datagrid at OnItemDataBound xzzy ASP .Net 3 06-18-2006 06:03 PM
Complex data binding question, binding child objects of a custom collection. JcFx ASP .Net Datagrid Control 0 06-01-2005 04:01 PM
LateBinding vs. OnItemDatabound binding revisited Weston Weems ASP .Net 2 09-29-2004 01:16 AM
DataGrid OnItemDataBound problem in APS.NET C# Steven ASP .Net 1 07-09-2003 05:17 PM



Advertisments