ASP.NET DataGrid - How to access column count prior to rendering?
I have a datagrid with columns programatically populated. I need access to the columns to modify the sort expression prior to render, but the column count is 0 at every stage I try to access them. Break points are hit, but each check of the count = 0.
Have tried the following, accessing in various stages of the page / control life cycle, but in all instances, the column count is 0.
Any ideas?
protected void Page_PreRenderComplete( object sender, EventArgs e )
{
if (dgPriceInfo != null)
{
if (dgPriceInfo.Columns.Count > 0)
{
dgPriceInfo.Columns[0].SortExpression = "";
}
}
}
protected void Page_SaveStateComplete( object sender, EventArgs e )
{
if (dgPriceInfo != null)
{
if (dgPriceInfo.Columns.Count > 0)
{
dgPriceInfo.Columns[0].SortExpression = "";
}
}
}
protected void Page_Render( object sender, EventArgs e )
{
if (dgPriceInfo != null)
{
if (dgPriceInfo.Columns.Count > 0)
{
dgPriceInfo.Columns[0].SortExpression = "";
}
}
}
protected void DataGrid_OnPreRender( obj开发者_如何转开发ect sender, EventArgs e )
{
DataGrid dg = sender as DataGrid;
if (dg != null)
{
if (dg.Columns.Count > 0)
{
dg.Columns[0].SortExpression = "";
}
}
}
Can you set the column's sort expression when you are adding columns programmatically?
精彩评论