Harlem 98

Harlem 98

  • 1.9k
  • 161
  • 3.7k

Disabling Insert button when grid is empty/edit mode

Nov 9 2021 6:34 PM

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

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.

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;
}}

Answers (2)