codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Column count  sardinka at 19:17 on Thursday, November 04, 2004
 

I have questions regarding data grid control. I am binding the data at run time to the data grid.
How can I find out number of columns after binding? What even would handle this?
My binding:
grdTransaction.DataSource = DataSet
grdTransaction.DataBind()
Column: grdTransaction.Columns.Count.ToString


  Re: Column count  tgreer at 19:22 on Thursday, November 04, 2004
 

The DataBinding event.


  Re: Column count  sardinka at 15:03 on Monday, November 08, 2004
 

I am doing on grid_ItemDataBound event this code
If e.Item.ItemType = ListItemType.AlternatingItem.Header Then
e.Item.Cells(0).ForeColor = Color.White
End If
It is always for the first column. How do I do for unknown count column?

  Re: Column count  tgreer at 19:37 on Monday, November 08, 2004
 

What's wrong with the code you previously posted?

grdTransaction.Columns.Count.ToString


  Re: Column count  tgreer at 21:47 on Monday, November 08, 2004
 

Don't use the ItemDataBound event, use the DataBinding event of the DataGrid itself.

HTML:

<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 24px" runat="server" OnDataBinding="countCols">


C#/ASP.NET:

public void countCols(object sender, System.EventArgs e)
{
string x = DataGrid1.Columns.Count.ToString();
}




  Re: Column count  tgreer at 21:48 on Monday, November 08, 2004
 

Don't use the ItemDataBound event, use the DataBinding event of the DataGrid itself.

HTML:

<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 24px" runat="server" OnDataBinding="countCols">


C#/ASP.NET:

public void countCols(object sender, System.EventArgs e)
{
string x = DataGrid1.Columns.Count.ToString();
}






© Copyright codetoad.com 2001-2004