Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read only for column in gridview

Tags:

c#

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/////////////////   
            }
        }
    }
}
like image 507
Myworld Avatar asked Dec 22 '22 00:12

Myworld


2 Answers

EDIT:

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

e.g.

WinForms DataGridView

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

WebForms GridView

((BoundField)gridView1.Columns[columnIndex]).ReadOnly = true;
like image 177
Iain Ward Avatar answered Jan 05 '23 16:01

Iain Ward


 DataGridViewColumn column;
 column.ReadOnly = true;
like image 45
Arseny Avatar answered Jan 05 '23 17:01

Arseny