tags:

views:

24

answers:

1

Hi,

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( object sender, EventArgs e )
{
    DataGrid dg = sender as DataGrid;

    if (dg != null)
    {
        if (dg.Columns.Count > 0)
        {
            dg.Columns[0].SortExpression = "";
        }
    }
}
A: 

Can you set the column's sort expression when you are adding columns programmatically?

brent-hauble