ayha1999
asked on
Checkboxlist
Hi,
I have checkboxList control in a form with the follwoing data
1,2,3,4,5 and 6 (values and texts)
in a table column I have only 1,3 and 5
How can I set 1,3 and 5 as selected in the checkboxlist in the page load event.
ayha
I have checkboxList control in a form with the follwoing data
1,2,3,4,5 and 6 (values and texts)
in a table column I have only 1,3 and 5
How can I set 1,3 and 5 as selected in the checkboxlist in the page load event.
ayha
ASKER
Hi brdrok,
I have to read data from a table and assign to the chekcboxlist.
ayha
I have to read data from a table and assign to the chekcboxlist.
ayha
gotcha. what does your sql query look like?
ASKER
HI,
select typenos from mytable
ayha
select typenos from mytable
ayha
try something like the following:
SqlConnection cn;
SqlCommand cmd;
string sql = "select typenos from mytable"
cn = new SqlConnection(Configuratio nSettings. AppSetting s["YourCon nectionStr ing"]);
cmd = new SqlCommand(sql, cn);
cn.Open();
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
if( (string) reader[0] = "1")
this.chkMyCheckBoxList.Ite ms[0].Sele cted == true;
if( (string) reader[0] = "2")
this.chkMyCheckBoxList.Ite ms[1].Sele cted == true;
etc.
}
on second thought..maybe a switch statement would be much more appropriate...but I have a cold and brain is starting to shut down =)
SqlConnection cn;
SqlCommand cmd;
string sql = "select typenos from mytable"
cn = new SqlConnection(Configuratio
cmd = new SqlCommand(sql, cn);
cn.Open();
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
if( (string) reader[0] = "1")
this.chkMyCheckBoxList.Ite
if( (string) reader[0] = "2")
this.chkMyCheckBoxList.Ite
etc.
}
on second thought..maybe a switch statement would be much more appropriate...but I have a cold and brain is starting to shut down =)
ASKER
Hi,
Any other way to do it without mentioning values like;
if( (string) reader[0] = "1")
this.chkMyCheckBoxList.Ite ms[0].Sele cted == true;
all values in the table will be available in the list. I want to select the values accordingly.
ayha
Any other way to do it without mentioning values like;
if( (string) reader[0] = "1")
this.chkMyCheckBoxList.Ite
all values in the table will be available in the list. I want to select the values accordingly.
ayha
what is your criteria for selecting whether a checkbox is checked or not? I thought this was determined via the database. So, if your query returns
1
3
5
and those will be selected in your checkbox list control, no?
1
3
5
and those will be selected in your checkbox list control, no?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if(!Page.IsPostBack)
{
this.chkMyCheckBoxList.Ite
this.chkMyCheckBoxList.Ite
this.chkMyCheckBoxList.Ite
}