GridView的模板列有条件地设置为只读 [英] GridView template Column conditionally set to readonly

查看:317
本文介绍了GridView的模板列有条件地设置为只读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来设置一个GridView模板列从code为只读落后。
就像如果测试管理​​员=真化妆只读=否则返回false只读=真正的

Is there a way to set a Template Column on a GridView to readonly from code behind. Like if test for Admin=true make readonly= false else readonly = true?

推荐答案

有没有直接的方法来设置 GridView控件列只读。但你可以设置在你的 GridView控件的RowDataBound 事件列只读的控件。例如。

There is no direct way to set the GridView column to readonly. But You can set the controls to readonly that are in that column in the RowDataBound event of your GridView. e.g.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowState == DataControlRowState.Edit || e.Row.RowState == DataControlRowState.Alternate)
    {
        TextBox txt = (TextBox)e.Row.FindControl("ControlID");
        txt.ReadOnly = true;
    }
}

这篇关于GridView的模板列有条件地设置为只读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆