Changes made in RadGrid_DataBound Event handler not rendered

6 posts, 1 answers
  1. T. Stanley
    T. Stanley avatar
    22 posts
    Member since:
    Sep 2007

    Posted 02 Sep 2009 Link to this post

    Hello.

    I am converting a page using asp:GridView to a RadGrid control and am having trouble with the latter's server side event DataBound.  In the GridView, I have used the DataBound to alter the HeaderText of a particular column based on the value of a Session variable:


    protected
    void scheduleGridView_DataBound(object sender, EventArgs e)

    {

     

     

    // Set the correct label on the data grid using session variable

     

     

     

    if (clinTypeID == 1) //MD

     

     

     

    {

     

    scheduleGridView.Columns[0].HeaderText = 

    "MD";
    }

     

     

     

    else //CRNA

     

     

     

    {

     

    scheduleGridView.Columns[0].HeaderText = 

    "CRNA";

     

     

    }}

    Exactly the same code is used with the RadGrid:

     


    protected
    void scheduleRadGrid_DataBound(object sender, EventArgs e)

    {

     

    // Set the correct label on the RadGrid using session variable

     

     

     

     

    if (clinTypeID == 1) //MD

     

     

     

     

    {

     

     

    scheduleRadGrid.Columns[0].HeaderText = 

    "MD";
    }

     

     

     

    else //CRNA

     

     

     

     

    {

     

     

    scheduleRadGrid.Columns[0].HeaderText = 

    "CRNA";

     

     

     

    }}

    This does not work for the RadGrid.  I set a breakpoint in this code and confirmed that the HeaderText value IS being changed.  However, this is not reflected when the control is rendered.  What could I be missing?  Thanks!

    Tom Stanley

     

  2. T. Stanley
    T. Stanley avatar
    22 posts
    Member since:
    Sep 2007

    Posted 02 Sep 2009 Link to this post

    More on this issue... having enabled sorting on the column with the altered HeaderText, when I click on the header, it sorts and changes the text to the new string.  It's as if the DataBound handler fired after the RadGrid was set to be rendered.  Do I need to be targeting a different event?  Hope this helps.

    Tom Stanley
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 04 Sep 2009 Link to this post

    Hello T. Stanley,

    I recommend that you use the ItemCreated event instead of the ItemDataBound event.
    For more information, please check out the Distinguishing the major differences between ItemCreated and ItemDataBound events help topic.

    Sincerely yours,
    Mira
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. T. Stanley
    T. Stanley avatar
    22 posts
    Member since:
    Sep 2007

    Posted 04 Sep 2009 Link to this post

    Thanks for your response.

    I am actually not using the "ItemDataBound" event, but the "DataBound" event for the grid.  Nonetheless, when I move the text altering code to either the ItemDataBound or ItemCreated event, I get the same problem.  The header text renders as the static default for the column.  Only when I click on the header (to initialte sorting) does the text redisplay to show as the text I have changed to in the event handler code.  Interestingly, I cannot get either of these Item handlers to respond to a breakpoint set within them.  So I cannot see what the code is doing.  I have the grid under Ajax management.  Is this why?  Thank you for your help.

    Tom Stanley
  6. Answer
    Mira
    Admin
    Mira avatar
    1124 posts

    Posted 09 Sep 2009 Link to this post

    Hi Tom,

    Would please try changing the column header's text in the grid's PreRender event handler and rebind the grid?
    Your code should look like:
    protected void RadGrid1_PreRender(object sender, EventArgs e) 
        { 
            RadGrid1.Columns[0].HeaderText = "NameChanged"
            RadGrid1.Rebind(); 
        } 

    Sincerely yours,
    Mira
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. T. Stanley
    T. Stanley avatar
    22 posts
    Member since:
    Sep 2007

    Posted 09 Sep 2009 Link to this post

    Thank you.  Placing the code in the PreRender event seems to work.

    Tom Stanley
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017