Read only for a column in gridview

I had a Gridview bind sqldatasource, and I had logins that see gridview, and I created roles for these logins, from which someone does not see the entire gridview column, so how can I only make some columns.?

public void code 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///////////////// } } } } 
+4
source share
2 answers

EDIT:

All you have 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; 
+8
source
  DataGridViewColumn column; column.ReadOnly = true; 
+2
source

All Articles