简体   繁体   中英

Read only for column in gridview

I had Gridview bind sqldatasource and I had logins which see gridview and I made roles for these logins som of them cannot see all gridview column so how can I make some columns read only .?

code 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/////////////////   
            }
        }
    }
}

EDIT:

All you need to do is set the ReadOnly property to true

eg

WinForms DataGridView

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

WebForms GridView

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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