Click here to Skip to main content
15,917,177 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Design :


XML
<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>

Code Behind :
C#
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();
    }
}
Posted
Updated 21-Dec-11 5:49am
v2
Comments
sriman.ch 15-Dec-11 5:26am    
Whats your question ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900