Click here to Skip to main content
15,917,176 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hi!
I want to know how to add checkbox(input html control) which will be appear dynamically in datatable.Can anyone explain it?

Snow
Posted

1 solution

Please let me know which control you are using to render the checkbox?

I assume that you are using GridView control.
In this case you have to add column in Datatable of Boolean datatype.

DataTable dt=new DataTable();<br />
dt.Columns.add("Col1",String);<br />
dt.Columns.add("Col2",Boolean);//This column will be display as CheckBox<br />
<br />
GridView1.DataSource= dt;<br />
GridView1.DataBind();


Hope this help you.
 
Share this answer
 
Comments
Member 7803337 1-Apr-11 1:25am    
Thanks!.I'm using the jquery datatable.This is part of asp.net code i'm writing.

Dataset rResult;
protected void Page_Load(object sender, EventArgs e)
{
int sEcho = int.Parse(Request.QueryString["sEcho"]);
int iResultCount = 0;
/*I firstly get the required dataset result using sql select statement from table of database.*/
rResult = bolemp.select_employeelist(DisplayStart, DisplayLength, int.Parse(cri_ddlpolicy), sort_str, ref iResultCount);
int iTotal = iResultCount;

soutput = "{";
soutput += "'sEcho': " + sEcho + ", ";
soutput += "'iTotalRecords': " + iTotal + ", ";
soutput += "'iTotalDisplayRecords': " + iTotal + ", ";
soutput += "'aaData': [ ";

for (int i = 0; i < rResult.Tables[0].Rows.Count; i++ int enrollnum =int.Parse(rResult.Tables[0].Rows[i]["EnrollNumber"].ToString());
soutput += "[";
soutput += "\'" + enrollnum+ "\',";

/*this statement I'm having trouble*/
soutput += "'<input id='chk' name='chk" + enrollnum + "' type='checkbox' class='chkclass' value='" + enrollnum + "'>'";
soutput += "],";
......
}
soutput = soutput.Remove(soutput.Length - 1);
soutput += "] }";
Response.Write(soutput);
}

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