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