You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过CodeBehind禁用Telerik Grid指定行LnkButton的超链接

实现指定行禁用HypUName超链接的方案

首先确保你的CodeBehind文件已引入Telerik控件对应的命名空间:

using Telerik.Web.UI;

步骤1:给Grid绑定行数据绑定事件

在你的Telerik RadGrid前端标签上添加ItemDataBound事件绑定:

<telerik:RadGrid ID="你的GridID" runat="server" OnItemDataBound="Grid_ItemDataBound"
    <!-- 保留你原有Grid的其他配置属性 -->
>
    <!-- 你原有Grid的列、模板等其他代码 -->
</telerik:RadGrid>

步骤2:编写后台事件处理逻辑

在CodeBehind中实现事件方法,按照你的业务条件判断哪些行需要禁用超链接:

protected void Grid_ItemDataBound(object sender, GridItemEventArgs e)
{
    // 仅处理数据行,过滤表头、分组行、脚注等非数据行
    if (e.Item is GridDataItem currentRow)
    {
        // 查找当前行内的HypUName控件
        LnkButton hypUName = currentRow.FindControl("HypUName") as LnkButton;
        if (hypUName == null) return;

        // 替换为你自己的业务判断规则,示例为判断当前行的IsDisable字段值为1时禁用
        bool needDisable = Convert.ToBoolean(DataBinder.Eval(currentRow.DataItem, "IsDisable"));
        if (needDisable)
        {
            // 方式1:完全移除超链接效果,和你手动删除该控件的效果一致
            hypUName.Visible = false;
            // 如果需要显示纯文本,可以同时显示同模板内的LnkButton1
            // LnkButton lnkBtn1 = currentRow.FindControl("LnkButton1") as LnkButton;
            // lnkBtn1.Visible = true;

            // 方式2:仅禁用点击,保留文本显示为灰化不可点击状态
            // hypUName.Enabled = false;
            // hypUName.Attributes.Add("style", "color:#999;cursor:default;pointer-events:none;");
        }
    }
}

你可以根据实际需求选择对应的禁用方式,业务判断条件也可以灵活调整为任意行数据相关的规则。

内容的提问来源于stack exchange,提问作者Greg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 10:27:02