<asp:GridView ID="GridView1" runat="server"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:CheckBox ID="CheckBox1" Enabled='<%# Eval("Access") %>' runat="server" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data; public partial class Display : System.Web.UI.Page { SqlConnection con = new SqlConnection(@"Data Source=MAJ-056\SQLEXPRESS;Initial Catalog=SmapleDB;Integrated Security=True"); protected void Page_Load(object sender, EventArgs e) { if (Session["UserType"] == null) { Response.Redirect("Login.aspx"); } if (!IsPostBack) { BindGrid(); } } private void BindGrid() { int userType = Convert.ToInt32(Session["UserType"]); con.Open(); SqlCommand cmd = new SqlCommand("select * from tblSol", con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); ds.Tables[0].Columns.Add(new DataColumn("Access", typeof(bool))); int i=0; foreach (DataRow item in ds.Tables[0].Rows) { if (Convert.ToInt32(item["UserType"]) == userType) { ds.Tables[0].Rows[i]["Access"] = true; } else { ds.Tables[0].Rows[i]["Access"] = false; } i++; } GridView1.DataSource = ds; GridView1.DataBind(); con.Close(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)