Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,


how can we bind checkboxes to the gridview dynamically according to the monthdays using datatables

eg:attendance register of schools

thanks in advance
Posted
Comments
Bhushan Shah1988 2-May-13 7:11am    
what you want to do?

Please describe in details.
Swetha Bisa 2-May-13 7:25am    
actually i want to bind checkboxes dynamically to gridview using datatable. dates of month should also bind as header in each row and ids of employees to the left
Thanks7872 2-May-13 7:33am    
not clear what you wana do?row doesnt have HEADER?post the code you have tried yet.

1 solution

Manually add checkbox into GridView:
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        System.Data.DataTable dt = GetTable();
        ViewState["dt"] = dt;
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }

    AddCheckBox(); 
}

void AddCheckBox()
{
    System.Data.DataTable dt = (System.Data.DataTable)ViewState["dt"];
    for (int i = 0; i < dt.Rows.Count; i++)
    {
        if (GridView1.Rows[i].Cells[0].Controls.Count == 0)
        {
            CheckBox cb = new CheckBox();
            GridView1.Rows[i].Cells[0].Controls.Add(cb);
        }
    }
}

void GetCheckBoxValue()
{
    foreach (GridViewRow gr in GridView1.Rows)
    {
        bool cbValue = ((CheckBox)gr.Cells[0].Controls[0]).Checked;

        // do something
    }
}
 
Share this answer
 

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