c# - 只读 gridview 中的列

标签 c#

我有 Gridview 绑定(bind) sqldatasource,我有可以看到 gridview 的登录名,我为这些登录名创建了角色,其中一些无法看到所有 gridview 列,所以我怎样才能让一些列只读。?

代码 公共(public)无效 CheckLoginAuthorty() {

    using (SqlConnection Con = Connection.GetConnection())
    {
        SqlCommand com = new SqlCommand("CheackLoginInRole", Con);
        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add(Parameter.NewNVarChar("@Login", Session.Contents["Username"].ToString()));
        object O = com.ExecuteScalar();

        if (O != null)
        {
            string S = O.ToString();

            if (IsInRole("AR-Translator", O.ToString()))
            {
            ///////// Grideview code/////////////////   
            }

            else if (IsInRole("EN-Translator", O.ToString()))
            {
       /////////Grideview code/////////////////   
            }
        }
    }
}

最佳答案

编辑:

您需要做的就是将 ReadOnly 属性设置为 true

例如

WinForms 数据 GridView

dataGridView1.Columns["ColumnName"].ReadOnly = true;

WebForms GridView

((BoundField)gridView1.Columns[columnIndex]).ReadOnly = true;

关于c# - 只读 gridview 中的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3343073/

相关文章:

c# - 如何为 MSI 提供卸载选项或设置为应用程序创建的文件

c# - 连接字符串中下划线后的数据库名称被忽略

c# - API 选择,我应该返回 XPathNavigator 还是 XmlDocument

c# - WinForms 中的 RX 和 Model-View-Presenter

c# - 可以创建 key 未知的通用搜索方法

c# - System.Data.SqlClient.SqlException : Cannot insert the value NULL into column 'IngredientId' , 表 'RecipeApplicationDb.dbo.IngredientModels' ;

c# - 什么时候在 C# 中调用静态构造函数?

c# - 看不到无限循环

c# - 使用 C# 在 Skype 上错过聊天

c# - 与point相比,pointf是否四舍五入?