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

When is Rebind necessary in PreRender

4 Answers 163 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Al
Top achievements
Rank 1
Iron
Iron
Iron
Al asked on 03 Jun 2015, 09:36 AM

Hi,

I have seen that sets grid properties in PreRender and there is no Rebind but then others (eg. setting header text) that do require ReBind. What are the cases then that will require a call to Rebind for the properties to be set properly?

 

Why I ask: PreRender is so handy because I can handle all grid localization in one call, for both Programmatic and Declarative grids. Rebinding though causes selected rows to get lost so I cannot use that & the only options other than PreRender are to use a combination of Page_Load, ColumnCreated, ItemCreated, ItemDataBound to properly localize all grid items for Programmatic and Declarative grids.

4 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 08 Jun 2015, 09:40 AM
Hi Al,

Some grid settings are applied before the the grid is bound. Therefore, setting their corresponding properties in a late event handler like PreRender won't have effect until the next postback.

In order to achieve your original requirement, you will need to change the text of the header cell directly. In order to do that, you can make avail of the GetItems() method:
http://www.telerik.com/help/aspnet-ajax/grid-using-getitems-getcolumn-methods.html

In your case it will be something similar to this:
Copy Code
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    GridHeaderItem headerItem = RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0] as GridHeaderItem;
    headerItem["ShipName"].Text = "Success";
}

Hope this helps. Please give it a try and let me know if it works for you.


Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Al
Top achievements
Rank 1
Iron
Iron
Iron
answered on 10 Jun 2015, 10:55 AM

Thanks Eyup - is there any way to access the UniqueName of a GridHeaderItem?

The problem is that I don't always know the names of the columns and I want to localize - how can I iterate through GridHeaderItems and look for a UniqueName?

0
Al
Top achievements
Rank 1
Iron
Iron
Iron
answered on 10 Jun 2015, 02:46 PM

Hi Eyup,

After some reading I think I have found a solution that will work in PreRender for programmatic and declarative grids, localizing column headers based on iteration and using the UniqueName attribute. I'll post here for anyone that may be interested, please comment if you see any problems with my approach.

GridHeaderItem headerItem = grd.MasterTableView.GetItems(GridItemType.Header)[0] as GridHeaderItem;
foreach (GridColumn column in grd.MasterTableView.RenderColumns)
{
    if (column is GridBoundColumn)
    {
        var item = headerItem[column.UniqueName];
 
        if (item.HasControls() && (item.Controls[0] is LinkButton))
        {
            (item.Controls[0] as LinkButton).Text = "abc";
        }
        else
        {
            item.Text = "abc";
        }
    }
}
 

 

0
Eyup
Telerik team
answered on 15 Jun 2015, 07:55 AM
Hello Al,

I'm glad you've managed to find a viable solution for your case.
Using the RenderColumns is the ideal approach. I guess you have Sorting enabled so you need to access the generated header LinkButton. Otherwise, you could simple set the Text property of the cell.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Al
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Eyup
Telerik team
Al
Top achievements
Rank 1
Iron
Iron
Iron
Share this question
or