This is a migrated thread and some comments may be shown as answers.

Column width resetting on AJAX call for programmatically generated columns

1 Answer 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tony
Top achievements
Rank 1
Tony asked on 13 Jun 2011, 11:11 PM
Hello,

I'm programmatically creating some columns in the Page_Load event (if not postback).  When I create these columns, I'm setting the width, such as:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GridBoundColumn boundColumn = new GridBoundColumn();
            boundColumn.HeaderStyle.Width = new Unit(100, UnitType.Pixel);
            boundColumn.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            boundColumn.ItemStyle.CssClass = "noWrapEllipsis";
            rgCool.MasterTableView.Columns.Add(boundColumn);
}
}


On the initial page load, everything is fine.  However, when an ajax call happens, such as on paging, the columns are still present in the grid, but their width setting is gone (I verified the TD elements have no width when rendered to the browser).

On the demo site is shows a grid persisting column widths across postbacks (or ajax calls).  How can I do this with programmatically created columns?  Should their properties be saved in viewstate just like when the columns are defined in the markup?

1 Answer, 1 is accepted

Sort by
0
Tony
Top achievements
Rank 1
answered on 14 Jun 2011, 12:11 AM
Silly me, I solved my own problem.  Reading through the documentation, I see my mistake was that I didn't add the column to the master view BEFORE setting its properties.  This is necessary in order for viewstate to be managed.  Once I did that, everything is fine.
Tags
Grid
Asked by
Tony
Top achievements
Rank 1
Answers by
Tony
Top achievements
Rank 1
Share this question
or