-1

我的页面有一个组合框,用于过滤网格值。我试图在组合框为空时禁用网格的“添加新记录”按钮,并在选择值时启用该按钮,随后加载网格。

我有以下 JavaScript 函数,它禁用了 pageLoad 上的按钮,但我以后无法启用该按钮。我应该怎么办?

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

在尝试了 PreRender 方法后,我尝试启用组合框“SelectedChangeIndex”上的按钮,但结果有任何结果。

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

2 回答 2

0

我通过在服务器端进行工作、使用grid_ItemDataBound事件、禁用按钮来解决这个问题:

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
}
于 2021-11-10T17:38:58.930 回答
0

在您的页面加载中,您是否调用了 GridBind?调用 Grid Bind 后,执行 RowCount 检查其是否为 0,然后关闭按钮。不要将按钮放在网格内部,只需在网格外部添加一个按钮,这样您就可以轻松引用它来关闭它。就像是:

Grid.Bind();
if(Grid.Rows.Count == 0)
{
   buttonID.Visible = false;
}
else
{
   buttonID.Visible = true;
}
于 2021-11-10T18:46:19.700 回答