Could anybody explain me Is anyway to implement following using UltraWebGrid?
Thanks
Hai,
I think the following link will help to create the template column
http://help.infragistics.com/Help/NetAdvantage/ASPNET/2009.1/CLR3.5/html/WebGrid_Templating.html
Thanks very much for your help!
I have investigated problem.
Header tempate instantiation occurs only after (or on) DataBinding (m_grid.DataBind()).
For example user clicks "Sort" button, in Sort button's event handler I get sorted data and do DataBind() to apply sort condition.
So in my case DataBind() may be occured in every time: Page_Load, Event handlers, Page_Prerender.
But method LoadPostData that loads information from post data occurs only after Page_Load stage So if I do DataBind() after Page_Load, method LoadPostData doesnt occur and my controls in header template loose their state.
For now I do LoadPostData for each control in templates by force. But it is not GOOD solution.
And the question is WHY header tempate controls are instantiated only after DataBind() method?
in addition from help:
Occurs when the grid is being data bound. Called by OnInitializeDataSource. By handling this event the application developers signals to the grid that the UltraWebGrid.DataBind method should be called automatically whenever the data is needed by the grid. No manual call of the method is required after that.
But I need do DataBind manually.
Hello Alexander,
I have changed the code for the example in this way and it works fine.
private void Page_Load(object sender, System.EventArgs e) { // If there is a query string, then this is a custom AJAX call, which means that the user has changed a // DropDownList selection from the Dropdown. if (!Page.IsPostBack){ if (Request.QueryString.Count > 0) { // Filter the DataView applyFilterOnDataView(); isFiltering = true; } }
}
I think that you need to handle in your code this condition to recreate the headers when postback is made in UltraWebGrid1_InitializeDataSource1 method for reference see the sample.
else if (this.IsPostBack && !this.UltraWebGrid1.IsXmlHttpRequest) { // 1: Get the DataView from the session state DataView dv = (DataView)Session["GridDataSource"]; // 2: Create templated columns for DropDownLists to show in each header createDropDownsForRowFiltering(dv); // Since we want the DropDownLists for the header template, we will create all columns in code this.UltraWebGrid1.DisplayLayout.AutoGenerateColumns = false; }
I hope this will help you.
Rado,
Developer support team
Infragistics
Add one additional question:
If I do data binding in PreRender method my template controls loose their state. Probably it is because state is restored from ViewState after Page_Load but before PreRender. Is anyway to load it by force?
void Page_Load() {InitColumns();}
void Page_PreRender() //controls state is not restored
{
m_grid.DataSource = ds.Tables[0].DefaultView; m_grid.DataBind();
Thanks, Rado!
I have investigated you sample, and faced with following problem:
I dynamically generate columns the same method as in you sample.
The problem is following:
When I do data binding each time all work fine, but if I do binding only on fist request InstantiateIn method did not rised and my column's headers all are empy.
void Page_Load() // Works fine{InitColumns();m_grid.DataSource = ds.Tables[0].DefaultView;m_grid.DataBind();}void Page_Load() //works only on first request{ InitColumns(); If(!IsPostBack) { m_grid.DataSource = ds.Tables[0].DefaultView; m_grid.DataBind(); }}
I cannot (don't want) do data binding on each request.
How can I fix it?