Hi,
I have a grid with a column with checkboxes in it. I need to remove the checkboxes for some rows and replace them with text. In the DataBindRow event I have code like this :-
TableCell Cell = Item["Select"];
Cell.Controls.Clear();
Label lb = new Label();
lb.Text = Msg;
Cell.Controls.Add(lb);
This works and the page looks fine. Until I do a postback on a button click. After the postback the grid now has check boxes on all rows - the rows that had them removed have them all back again. And the data bind was not even called on the postback.
Any ideas?
Clayton
I have a grid with a column with checkboxes in it. I need to remove the checkboxes for some rows and replace them with text. In the DataBindRow event I have code like this :-
TableCell Cell = Item["Select"];
Cell.Controls.Clear();
Label lb = new Label();
lb.Text = Msg;
Cell.Controls.Add(lb);
This works and the page looks fine. Until I do a postback on a button click. After the postback the grid now has check boxes on all rows - the rows that had them removed have them all back again. And the data bind was not even called on the postback.
Any ideas?
Clayton
4 Answers, 1 is accepted
0
Accepted

Princy
Top achievements
Rank 2
answered on 06 Aug 2009, 07:10 AM
Hi,
Try replacing the checkboxes with labels in the PreRender event of the grid as shown below:
c#:
Thanks
Princy.
Try replacing the checkboxes with labels in the PreRender event of the grid as shown below:
c#:
protected void RadGrid1_PreRender(object sender, EventArgs e) |
{ |
foreach (GridDataItem item in RadGrid1.MasterTableView.Items) |
{ |
if (item["Column"].Text == "Text")// check for condition |
{ |
item["Select"].Controls.Clear(); |
Label lbl = new Label(); |
lbl.Text = Msg; |
item["Select"].Controls.Add(lbl); |
} |
} |
} |
Thanks
Princy.
0

skysailor
Top achievements
Rank 1
answered on 07 Aug 2009, 12:35 AM
Hi,
I have managed to get this to work using your suggestion. It works because the DataBind event does not get caleld on postback. But the preRender one does. So it resets the checkboxes.
But this now casues another problem. I would like to remove the Checkbox in the header of the column. I was using the DataBind event to get the GridHeaderItem and updating the controls. This works on first post. But on postback the same issue occurs - the orignal controls are restored. Using the approach you suggested does not seem to work either. For some reason when I loop through the Items in the Grid there are only GridDataItems - not all the other items like GridHeaderItem. Any ideas how to get a reference to the header cells on PreRender?
Clayton
I have managed to get this to work using your suggestion. It works because the DataBind event does not get caleld on postback. But the preRender one does. So it resets the checkboxes.
But this now casues another problem. I would like to remove the Checkbox in the header of the column. I was using the DataBind event to get the GridHeaderItem and updating the controls. This works on first post. But on postback the same issue occurs - the orignal controls are restored. Using the approach you suggested does not seem to work either. For some reason when I loop through the Items in the Grid there are only GridDataItems - not all the other items like GridHeaderItem. Any ideas how to get a reference to the header cells on PreRender?
Clayton
0
Accepted
Hello skysailor,
You can get a reference to the header item as follows:
I hope this helps.
Best wishes,
Tsvetoslav
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
You can get a reference to the header item as follows:
GridHeaderItem item = RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0] as GridHeaderitem; |
if (item != null) |
{ |
....... |
} |
I hope this helps.
Best wishes,
Tsvetoslav
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0

skysailor
Top achievements
Rank 1
answered on 11 Aug 2009, 11:48 PM
Thankyou!
That works.
That works.