只读gridview中的列

时间:2010-07-27 11:23:51

标签: c#

我有Gridview绑定sqldatasource,我有登录看到gridview,我为这些登录创建了角色,他们看不到所有gridview列,所以我怎样才能让一些列只读。?

代码   public void 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/////////////////   
            }
        }
    }
}

2 个答案:

答案 0 :(得分:8)

修改

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

e.g。

WinForms DataGridView

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

WebForms GridView

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

答案 1 :(得分:2)

 DataGridViewColumn column;
 column.ReadOnly = true;