Loop through checkbox

Posted by Kashif under ASP.NET on 9/20/2013 | Points: 10 | Views : 1480 | Status : [Member] | Replies : 5
hi friends


i want to loop through checkbox using asp.net with c#...and also i want to get values from database in the checkbox....means all values of my require column of
table display at checkboxes....

Any idea...???




Responses

Posted by: Bandi on: 9/20/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
This link will provide u the way....
http://www.nullskull.com/q/10304245/how-to-bind-only-column-name-of-table-to-checklistbox-cntrl-in-aspnet.aspx

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Kashif, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/20/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
you can use repeater control for looping
http://www.aspdotnet-suresh.com/2012/01/repeater-control-example-in-aspnet.html

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Kashif, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kashif on: 9/21/2013 [Member] Starter | Points: 25

Up
0
Down
hi Chandu ...

i appritiate ur suggetions....bt these are not my solution...either i am not getting any thing from them.....i think u hv not understand my question..i now try it again to explain u ...
i require checkboxes ,name appear at each checkbox must be from database,and number of chekboxes depend upon number of entries in my column...simply i want to bind checkbox\(not in gridview or datagridview) with database and loop through it



Kashif
Learner of Asp.net




Kashif, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/23/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Means you would like to have checkboxlist which bounds based on table one column data?
bind data from database into checkboxlist at runtime?
private void CheckboxListBind()

{
SqlConnection conn = new SqlConnection("connection string");
conn.Open();
SqlDataReader dr;
SqlCommand cmd = new SqlCommand("SELECT ename FROM employee", conn);
dr = cmd.ExecuteReader();
while (dr.Read())
{
checkedListBox1.Items.Add(dr.GetValue(0).ToString());
}
conn.Close();
}


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Kashif, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/23/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

try this Code

DataRow dr;
Dt.Columns.Add("Id");
Dt.Columns.Add("Name");
dr = Dt.NewRow();
dr[0] = 1;
dr[1] = "JK";
Dt.Rows.Add(dr);
dr = Dt.NewRow();
dr[0] = 2;
dr[1] = "JK1";
Dt.Rows.Add(dr);

if (Dt.Rows.Count > 0)
{
string strConcate = "";
foreach (DataRow rw in Dt.Rows)
{
chk1.Items.Add(rw[0].ToString());
chk2.Items.Add(rw[1].ToString());
}
}

Mark as Answer if its helpful to you

Kashif, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response