C# Webforms:如何在代码隐藏中禁用Telerik RadGrid中的按钮
我是webforms的新手。我先学会了MVC。我有一个Telerik RadGrid,里面有一个MasterTableView,然后在这个MasterTableView里面有两列。我想简单地禁用代码隐藏中的一些按钮,但VisualStudio一直告诉我这些按钮不存在。在谷歌搜索中,我发现原因是因为按钮在RadGrid中。但是,我没有找到任何访问它们的示例 按钮位于radgrid内,它们看起来如下所示:C# Webforms:如何在代码隐藏中禁用Telerik RadGrid中的按钮,c#,asp.net,webforms,telerik,radgrid,C#,Asp.net,Webforms,Telerik,Radgrid,我是webforms的新手。我先学会了MVC。我有一个Telerik RadGrid,里面有一个MasterTableView,然后在这个MasterTableView里面有两列。我想简单地禁用代码隐藏中的一些按钮,但VisualStudio一直告诉我这些按钮不存在。在谷歌搜索中,我发现原因是因为按钮在RadGrid中。但是,我没有找到任何访问它们的示例 按钮位于radgrid内,它们看起来如下所示: <telerik
<telerik:GridTemplateColumn HeaderStyle-Width="72px" HeaderText="Acciones" >
<ItemTemplate >
<div style="width: 100px">
<span style="position:relative;" class="grid-buttonColor1">
<i class="material-icons">create</i>
<asp:Button ID="btnEditReportDetail"
CommandArgument='<%# Item.ReportDetailId %>'
OnClick="btnReportDetail_Click"
runat="server"
Style="position:absolute; opacity:0; top:0; left:0; width:100%; height:100%;"
type="button"
causesvalidation="false" />
</span>
<span style="position: relative;" class="grid-buttonColor2">
<button
type="button"
style="background-color: transparent; border: none; padding: 0"
data-toggle="modal"
data-target="#MessageBoxModal"
onclick="ShowMessageBoxWithMessage_<%= ucMessagebox.ClientID%>('Confirmación', '¿Está seguro que desea eliminar la tarea?','DeleteTaskReports','<%# Item.ReportDetailId.ToString() %>')">
<i class="material-icons prefix">delete</i>
</button>
</span>
</div>
</ItemTemplate>
</telerik:GridTemplateColumn>
创造
删除
我如何访问这些按钮,以便在代码中写入如下内容:buttonName.Enabled=false代码>
求你了!这快把我逼疯了
谢谢你们 也许这对你有帮助
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
Button btn = item.FindControl("img1") as Button;
btn.Enabled = false;
}
}
或
您需要使用FindControl
查找网格内部的服务器控件
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
Button button = e.Row.FindControl("Button1") as Button;
button.Enabled = false;
}
网格是否有服务器端数据绑定事件?如果是的话,我想你可能可以访问那里的按钮。只是胡乱猜测谢谢你的快速回答。你的第二个例子应该会有所帮助。只有一个问题。什么是“cmdItem”?这给我带来了一个错误。你的意思是在foreach中插入“dataItem”吗?是的,我更改了dataItem的cmdItem,现在它可以工作了。非常感谢。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
Button button = e.Row.FindControl("Button1") as Button;
button.Enabled = false;
}