locked
Checkbox Gridview Custom Control - help. RRS feed

  • Question

  • User1049375347 posted

    Hello,

    I am in the planning stages for a new .net control and am looking for feedback/tips. 

    What I am hoping to accomplish is a 'checkbox gridview matrix'.  I don't know if this is fesiable ( hoping to figure that part out with this posting ) but, what I would like have is a header and first column that would have text. then every other column would be a checkbox.

    example:

    Permissions   |  Admin       |  Users
    ----------------------------------------------------------
    Update Tables | [checkbox] | [checkbox]
    Select Data     | [checkbox] | [checkbox] 

    My current solution is to add the checkbox and set the value on rowdatabind.

    Any thoughts on this idea are welcome. I don't have the experience creating controls to really say for sure if this would be a good idea so I hope I could get some advice.

    Thanks
    Wednesday, June 1, 2011 8:59 PM

Answers

  • User-933246677 posted

    you can use a datatable then bind it to the gridview:

    protected void Page_Load(object sender, EventArgs e)
            {
                //create a datatable
                DataTable dt = new DataTable();
    
    
                //create columns
                dt.Columns.Add("Permissions", typeof(string));
                dt.Columns.Add("Admin", typeof(bool));
                dt.Columns.Add("Users", typeof(bool));
    
    
                //create rows
                DataRow row1 = dt.NewRow();
                row1["Permissions"] = "Update Tables";
    
                DataRow row2 = dt.NewRow();
                row2["Permissions"] = "Select Data";
    
                dt.Rows.Add(row1);
                dt.Rows.Add(row2);
    
    
                //bind the datatable to the gridview
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 3, 2011 9:51 AM

All replies

  • User-933246677 posted

    you can use a datatable then bind it to the gridview:

    protected void Page_Load(object sender, EventArgs e)
            {
                //create a datatable
                DataTable dt = new DataTable();
    
    
                //create columns
                dt.Columns.Add("Permissions", typeof(string));
                dt.Columns.Add("Admin", typeof(bool));
                dt.Columns.Add("Users", typeof(bool));
    
    
                //create rows
                DataRow row1 = dt.NewRow();
                row1["Permissions"] = "Update Tables";
    
                DataRow row2 = dt.NewRow();
                row2["Permissions"] = "Select Data";
    
                dt.Rows.Add(row1);
                dt.Rows.Add(row2);
    
    
                //bind the datatable to the gridview
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 3, 2011 9:51 AM
  • User3866881 posted

    Hello:)

    I agree what the 2nd man's idea——

    My additions——In my mind, GridView will use different kinds of BoundControl to show different kinds of things in itself.——e.g:string is usually shown in Label, while bool is shown with CheckBox.

    So if you want to make a CustomControl, Just put a GridView into the ascx and use it anywhere you like.

    Thx

    Friday, June 3, 2011 11:03 PM