skip to Main Content

My page has a comboBox which filters grid values. Im trying to disable grid’s "add new record" button, when comboBox is empty, and enable the button when a value is selected and subconsequently, grid is loaded.

I have the following JavaScript function, which disables the button on pageLoad, but i cant enable the button later. What should i do?

function pageLoad() {
                       var grid = $find("<%=grid1.ClientID %>");
                       Button1 = $telerik.findControl(grid.get_element(), "AddNewRecordButton");
                       Button1.set_visible(false);
                   }

I tried to enable the button on the comboBox "SelectedChangeIndex", after trying in the PreRender method, with any results.

        if (radcombobox1.SelectedValue != null)
{
    GridCommandItem cmditem = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
    Telerik.Web.UI.RadButton addbtn = (Telerik.Web.UI.RadButton)cmditem.FindControl("AddNewRecordButton");
    addbtn.Visible = true;
}

else
{
    // alert
} 

2

Answers


  1. Chosen as BEST ANSWER

    I solved this by doing the work on the server-side, using the grid_ItemDataBound event, disabling the button:

    if (RadComboBox1.SelectedItem == null) 
    {
    
        GridCommandItem cmditem = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
        Telerik.Web.UI.RadButton addbtn = (Telerik.Web.UI.RadButton)cmditem.FindControl("AddNewRecordButton");
        addbtn.Visible = false; //Enabled
    }
    

  2. In your page load do you call the GridBind? After you call the Grid Bind do a RowCount check if its 0 then turn off the button. Don’t put button the inside the Grid just add a button outside of it that way you can easily reference it to turn it off. Something like:

    Grid.Bind();
    if(Grid.Rows.Count == 0)
    {
       buttonID.Visible = false;
    }
    else
    {
       buttonID.Visible = true;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search