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

[Solved] Mastertable, Detailtable, ItemDataBound

1 Answer 123 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mk
Top achievements
Rank 1
mk asked on 02 Oct 2009, 05:59 PM
On ItemDataBound of the mastertable I am hiding the delete and edit columns for certains rows.
This part is working perfectly, except for when the detailtable is displayed. When the detailtable is displayed it rebinds the whole grid but does not call ItemDataBound for the mastertable so the delete and edit columns are displayed again.

protected void grdEvents_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem) 
            { 
                GridDataItem item = (GridDataItem)e.Item; 
                if (e.Item.OwnerTableView.Name == "EventsGrid")//This is the mastertable 
                { 
                    ProtocolRegimenEvent preItem = (ProtocolRegimenEvent)e.Item.DataItem; 
                    TableCell td = item[grdEvents.Columns.FindByUniqueNameSafe("colDelete")]; 
 
                    if (preItem.EventTypeId != (int)Enums.EventTypes.Scheduled) 
                    { 
                        if (td != null && td.Controls.Count > 0) 
                        { 
                            td.Controls.RemoveAt(0); 
                            Label lbl = new Label(); 
                            lbl.Text = "-"
                            td.Controls.Add(lbl); 
                        } 
                        if (preItem.EventTypeId == (int)Enums.EventTypes.Unscheduled) 
                        { 
                            td = item[grdEvents.Columns.FindByUniqueNameSafe("colEdit")]; 
                            if (td != null && td.Controls.Count > 0) 
                            { 
                                td.Controls.RemoveAt(0); 
                                Label lbl = new Label(); 
                                lbl.Text = "-"
                                td.Controls.Add(lbl); 
                            } 
                        } 
                    } 
                } 
                else //This is a detailtable 
                { 
                     ProtocolRegimenEventForm preItem = (ProtocolRegimenEventForm)e.Item.DataItem;

                    TableCell td = e.Item.OwnerTableView.ParentItem[grdEvents.Columns.FindByUniqueNameSafe("colDelete")];

                    if (preItem.EventTypeId != (int)Enums.EventTypes.Scheduled)
                    { //remove buttons
}
                } 
            } 
        } 

I can remove the edit and delete buttons for the parentItem but not any of the other rows. How do I remove it from the other rows?


1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 07 Oct 2009, 07:50 AM
Hello mk,

Indeed, the ItemDataBound event handler is not raised on each page cycle. Thus, another option in your case would be to use the PreRender event handler, which is raised on each page cycle - there you can iterate through all the items in the grid, and hide/show the relevant cells.
I hope this suggestion helps.

Greetings,
Yavor
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.
Tags
Grid
Asked by
mk
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or