When is Rebind necessary in PreRender

5 posts, 0 answers
  1. Al
    Al avatar
    221 posts
    Member since:
    Oct 2006

    Posted 03 Jun 2015 Link to this post

    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.

  2. Eyup
    Admin
    Eyup avatar
    3757 posts

    Posted 08 Jun 2015 Link to this post

    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
  3. Al
    Al avatar
    221 posts
    Member since:
    Oct 2006

    Posted 10 Jun 2015 in reply to Eyup Link to this post

    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?

  4. Al
    Al avatar
    221 posts
    Member since:
    Oct 2006

    Posted 10 Jun 2015 Link to this post

    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";
            }
        }
    }
     

     

  5. Eyup
    Admin
    Eyup avatar
    3757 posts

    Posted 15 Jun 2015 Link to this post

    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
Back to Top