|
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
|
|
|
|
|
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?
|
|
|
What's wrong with the code you previously posted?
grdTransaction.Columns.Count.ToString
|
|
|
|
|
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();
}
|
|
|
|
|
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();
}
|
|
|
|
|