繁体   English   中英

Webforms:如何在背后的代码中禁用Telerik RadGrid内部的按钮

[英]Webforms: How to disable a button that is inside a Telerik RadGrid in code behind

我是使用Webforms的新手。 我首先学习了MVC。 我有一个Telerik RadGrid,里面有一个MasterTableView,然后在这个MasterTableView中有几列。 我只想在后面的代码中禁用某些按钮,但是Visual Studio不断告诉我这些按钮不存在。 在Google搜索中,我发现原因是因为按钮位于RadGrid内部。 但是我没有找到任何访问它们的示例。

这些按钮位于radgrid内部,它们看起来像这样:

                                    <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>
                                                &nbsp;
                                                <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;            

    } 
 } 

要么

protected void RadGrid1_PreRender(object sender, EventArgs e)
{
if ("your Condition")
{
    foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items)
    {
        ((Button)cmdItem.FindControl("btnEditReportDetail")).Visible = false;
    }
}
}

您需要使用FindControl在Grid内部查找服务器控件。

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    Button button = e.Row.FindControl("Button1") as Button;
    button.Enabled = false;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM