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

Changes made in RadGrid_DataBound Event handler not rendered

5 Answers 128 Views
Grid
This is a migrated thread and some comments may be shown as answers.
T. Stanley
Top achievements
Rank 1
T. Stanley asked on 02 Sep 2009, 03:35 PM
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

 

5 Answers, 1 is accepted

Sort by
0
T. Stanley
Top achievements
Rank 1
answered on 02 Sep 2009, 04:15 PM
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
0
Mira
Telerik team
answered on 04 Sep 2009, 03:53 PM
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.
0
T. Stanley
Top achievements
Rank 1
answered on 04 Sep 2009, 08:07 PM
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
0
Accepted
Mira
Telerik team
answered on 09 Sep 2009, 11:51 AM
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.
0
T. Stanley
Top achievements
Rank 1
answered on 09 Sep 2009, 08:56 PM
Thank you.  Placing the code in the PreRender event seems to work.

Tom Stanley
Tags
Grid
Asked by
T. Stanley
Top achievements
Rank 1
Answers by
T. Stanley
Top achievements
Rank 1
Mira
Telerik team
Share this question
or