Hello community.
I want to disable mentioned buttons when user is in edit mode, or when grid is empty right after page load.
I've tried the following for when client is in Edit mode; //Button "RadButton" is integrated in CommandTemplate of TelerikRadGrid
C#
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.isInEditMode)
{
GridEditableItem item = (GridEditableItem)e.Item;foreach (GridCommandItem cmdItem in RadGrid1.MasterTableView.Getitems(GridItemType.CommandItem))
{
RadButton btn = (RadButton)cmdItem.FindControl("AddNewRecordButton");
btn.Enabled = false;
}}I've tried the following code for when the count of items is zero.
C#
protected void radgrid1_PreRender (object sender, EventArgs e)
{
Radbutton rb = new RadButton();
if (radgrid1.MasterTableView.Items.Count !=0)
{
foreach (GridItem item in RadGrid.MasterTableView.Getitems(GridItemType.CommandItem))
rb = item.FindControl("AddNewRecordButton") as RadButton;
rb.Visible = false;
}}
Sachin SinghRank #66 · 26.2K reputationPosted Nov 10, 2021, 12:12 AM EST
Srinivasan RamamoorthiRank #877 · 2.5K reputationPosted Nov 9, 2021, 11:15 PM EST
The code in prerender should work, add RadGrid.MasterTableView.Rebind().
Try removing the code from ItemDatabound()
protectedvoidRadGrid1_PreRender(objectsender, EventArgs e){foreach(GridDataItem dataIteminRadGrid1.Items){if(dataItem.OwnerTableView.Name =="TableName")dataItem.OwnerTableView.GetColumn("AddColumnUniqueName").Visible =false;