Hello,
I am trying to set the CommandItemDisplay property of the RadGrid in the DataBound event of the grid. I would like to hide the CommandItemDisplay if there are no items in the Grid. However, when I attempt to set the value programmatically, it seems to get ignored. In the code below, even when CommandItemDisplay is set to GridCommandItemDisplay.Top, it doesn't show up.
I am trying to set the CommandItemDisplay property of the RadGrid in the DataBound event of the grid. I would like to hide the CommandItemDisplay if there are no items in the Grid. However, when I attempt to set the value programmatically, it seems to get ignored. In the code below, even when CommandItemDisplay is set to GridCommandItemDisplay.Top, it doesn't show up.
protected void radGrid_DataBound(object sender, EventArgs e)
{
if (radGrid.Items.Count > 0)
{
radGrid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
}
else
{
radGrid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None;
}
}
Thanks for your help,
Erin
9 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 10 Jun 2008, 06:01 AM
Hi Erin,
Try the Code in the PreRender event and see whether it is working.
ASPX:
CS:
Shinu
Try the Code in the PreRender event and see whether it is working.
ASPX:
<telerik:radgrid id="RadGrid1" runat="server" OnPreRender="RadGrid1_PreRender" > |
CS:
protected void RadGrid1_PreRender(object sender, EventArgs e) |
{ |
//code here |
} |
Shinu
0

Erin
Top achievements
Rank 1
answered on 10 Jun 2008, 05:01 PM
Hi Shinu,
Thanks for your response. I tried moving the code to the Grid's PreRender event like you suggested but it is still being ignored. I tried moving it to the PageLoad just to see if it would work and it is ignored in that case also. I do not seem to be able to set it programmatically. When I set it declaratively in the aspx page, it works fine. Please advise.
Thanks for your help,
Erin
Thanks for your response. I tried moving the code to the Grid's PreRender event like you suggested but it is still being ignored. I tried moving it to the PageLoad just to see if it would work and it is ignored in that case also. I do not seem to be able to set it programmatically. When I set it declaratively in the aspx page, it works fine. Please advise.
Thanks for your help,
Erin
0
Hello Erin,
Indeed, you can use the PreRender event handler to cater for this functionality.
However, this approach may require a rebind. Another option is to simply get a reference to the CommandItem (RadGrid1.MasterTableView.GetItems) handler, and simply hide it (display/visible=false).
Sincerely yours,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Indeed, you can use the PreRender event handler to cater for this functionality.
However, this approach may require a rebind. Another option is to simply get a reference to the CommandItem (RadGrid1.MasterTableView.GetItems) handler, and simply hide it (display/visible=false).
Sincerely yours,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0

Shinu
Top achievements
Rank 2
answered on 11 Jun 2008, 07:16 AM
Hi,
Try the following code snippet.
CS:
Shinu.
Try the following code snippet.
CS:
protected void RadGrid1_PreRender(object sender, EventArgs e) |
{ |
radGrid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None; |
radGrid.Rebind(); |
} |
Shinu.
0

Erin
Top achievements
Rank 1
answered on 11 Jun 2008, 09:25 PM
Hi Shinu and Yavor,
Thank you both for your replies. Calling Rebind on the grid should work but that is not a good option in terms of performance so I wanted to follow up with what Yavor suggested 1st if possible. I would like to clarify how to do that because I don't see a GetItems handler for the MasterTableView. I thought you had to access the grid command items from the ItemDataBound event of the grid, which unfortunately fires too early for me to know if the grid contains items or not so I can't use that function. Can you send me a quick example of what you suggested?
Thanks for your help,
Erin
Thank you both for your replies. Calling Rebind on the grid should work but that is not a good option in terms of performance so I wanted to follow up with what Yavor suggested 1st if possible. I would like to clarify how to do that because I don't see a GetItems handler for the MasterTableView. I thought you had to access the grid command items from the ItemDataBound event of the grid, which unfortunately fires too early for me to know if the grid contains items or not so I can't use that function. Can you send me a quick example of what you suggested?
Thanks for your help,
Erin
0

Shinu
Top achievements
Rank 2
answered on 12 Jun 2008, 06:31 AM
Hi Erin,
Try the following code snippet and see whether it is working.
CS:
Thanks
Shinu
Try the following code snippet and see whether it is working.
CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
foreach (GridCommandItem cmditm in RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)) |
{ |
if (RadGrid1.Items.Count > 0) |
{ |
cmditm.Display = true; |
} |
else |
cmditm.Display = false; |
} |
} |
Thanks
Shinu
0

Erin
Top achievements
Rank 1
answered on 12 Jun 2008, 12:41 PM
Hi Shinu,
Thanks for your reply. Unfortunately as I explained in my last post, the ItemDataBound event occurs prior to the Grid DataBound event so Grid.Items.Count is always 0 in ItemDataBound so that code doesn't work. It sounds like I have to make the Grid rebind again which seems pretty unnecessary. Are you going to have a fix for this in an future release?
Thanks,
Erin
Thanks for your reply. Unfortunately as I explained in my last post, the ItemDataBound event occurs prior to the Grid DataBound event so Grid.Items.Count is always 0 in ItemDataBound so that code doesn't work. It sounds like I have to make the Grid rebind again which seems pretty unnecessary. Are you going to have a fix for this in an future release?
Thanks,
Erin
0
Accepted
Hello Erin,
I have attached small example to illustrate you how to achieve this.
Kind regards,
Vlad
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
I have attached small example to illustrate you how to achieve this.
Kind regards,
Vlad
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0

Erin
Top achievements
Rank 1
answered on 13 Jun 2008, 05:23 PM
Hi Vlad,
Thanks so much for your reply and for sending the sample code. I added the code to the Page_PreRender instead of Page_PreRenderComplete which wasn't firing and it still works fine. So now I have the desired behavior without having to sacrifice performance.
Thanks again!
Erin
Thanks so much for your reply and for sending the sample code. I added the code to the Page_PreRender instead of Page_PreRenderComplete which wasn't firing and it still works fine. So now I have the desired behavior without having to sacrifice performance.
Thanks again!
Erin