You can easily add checkbox items to your form dynamically by using database as follows
int X=50;
CheckBox[] L;
SqlConnection con = new SqlConnection("user id=sa;password=;database=college");
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter("select * from studentdata", con);
DataSet ds = new DataSet();
da.Fill(ds, "studentdata");
L = new CheckBox[ds.Tables[0].Rows.Count];
for (int i = 0; i < ds.Tables[0].Rows.Count;i++)
{
L[i] = new CheckBox();
L[i].Text = ds.Tables[0].Rows[i].ItemArray.GetValue(0).ToString();
L[i].Location = new Point(100, x);
this.Controls.Add(L[i]);
}
No comments:
Post a Comment