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();
}











CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  shopping cart
•  File save when generating excel using ASP
•  Re: Menu Problems
•  Re: Help: Trouble with z-Index and SELECT lists
•  Problen encounter when generate excel file using ASP
•  Re: Column count
•  AutoScoll
•  Re: email validation problem
•  Re: database and time date expire


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2004