Click here to Skip to main content
14,970,669 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I have 1 checkbox list in that one check box is mobiles and another one is Laptops.
If I check on mobile It wil brings all mobile from DB to My DAtList
If I check on laptop It wil brings all mobile from DB to My DAtList
Here id the code
.aspx
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged">
<asp:ListItem Value="0">Mobiles
<asp:ListItem Value="1">Laptop

.aspx.cs
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{

List<string> GetList = new List<string>();
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected)
{
GetList.Add(item.Value);
}
}
string str = "select * from ProductDetails where Producttype=@textInput";
SqlCommand cmd = new SqlCommand(str, con);
cmd.Parameters.Add(new SqlParameter("@textInput", 0));
for (int d = 0; d < GetList.Count; d++)
{
string text = GetList[d];
cmd.Parameters["@textInput"].Value = text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if (count == 0)
{

dc = ds.Clone();
count++;
}
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (ds.Tables[0].Rows[i].ItemArray[0].ToString() != "NULL")
dc.Tables[0].ImportRow(ds.Tables[0].Rows[i]);
}
DataList1.DataSource = ds.Tables[0].DefaultView;
DataList1.DataBind();
}
}
}
Posted
Comments
Namith Krishnan E 12-Aug-14 23:56pm
   
what is the error?
Mayank Vashishtha 13-Aug-14 1:55am
   
OK! And Then?

1 solution

Check syntax of
GetList.Add(item.Value);
   

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