string strlocation = strlocation = "blank";
if (!IsPostBack)
foreach (ListItem li in CheckBoxList1.Items)
{
if (li.Selected == true)
{
strlocation = strlocation + "," + li.Text;
}
}
SqlConnection con = new SqlConnection("Data Source=PRAVEEN-PC;Initial Catalog=jobs;Integrated Security=True");
con.Open ();
SqlCommand cmd = new SqlCommand ("SELECT * FROM a3 WHERE '"+strlocation +"'LIKE[Location]");
dn631
Member
6 Points
39 Posts
how to use chkboxlist...........
Dec 07, 2012 04:55 AM|LINK
how to use checkboxlist and get only the selected Checkboxlist Location data into the gridview
pratik_galor...
Participant
1483 Points
330 Posts
Re: how to use chkboxlist...........
Dec 07, 2012 04:59 AM|LINK
//to get only selected data foreach (CheckBox chk in chkList1.Items) { if (chk.Selected) { // your code here } }Software Engineer,
iGATE Global Solutions.
pratik_galoria@yahoo.co.in
+91-8905195943
urenjoy
Star
13485 Points
2032 Posts
Re: how to use chkboxlist...........
Dec 07, 2012 05:01 AM|LINK
You can take idea from following threads:
http://forums.asp.net/t/1839256.aspx/1
http://forums.asp.net/t/1657982.aspx/1
http://www.4guysfromrolla.com/articles/012010-1.aspx
dn631
Member
6 Points
39 Posts
Re: how to use chkboxlist...........
Dec 07, 2012 05:09 AM|LINK
thnaks for the reply bro......
even i got that......i dont know how to bind gridview to that
dn631
Member
6 Points
39 Posts
Re: how to use chkboxlist...........
Dec 07, 2012 05:10 AM|LINK
ok thanks for the reply....
i ll read them
oned_gk
All-Star
36074 Points
7361 Posts
Re: how to use chkboxlist...........
Dec 07, 2012 06:27 AM|LINK
string strlocation = strlocation = "blank"; foreach (ListItem li in CheckBoxList1.Items) { if (li.Selected == true) { strlocation = strlocation + "," +li.Text; } }Suwandi - Non Graduate Programmer
dn631
Member
6 Points
39 Posts
Re: how to use chkboxlist...........
Dec 07, 2012 06:46 AM|LINK
i used a button and used this on click....
protected void Button1_Click(object sender, EventArgs e)
{
string strlocation = strlocation = "blank";
if (!IsPostBack)
foreach (ListItem li in CheckBoxList1.Items)
{
if (li.Selected == true)
{
strlocation = strlocation + "," + li.Text;
}
}
string sqlquery = "SELECT FROM a3 WHERE '" + strlocation + "'LIKE [Location]";
}
dn631
Member
6 Points
39 Posts
Re: how to use chkboxlist...........
Dec 07, 2012 07:09 AM|LINK
string strlocation = strlocation = "blank";
if (!IsPostBack)
foreach (ListItem li in CheckBoxList1.Items)
{
if (li.Selected == true)
{
strlocation = strlocation + "," + li.Text;
}
}
SqlConnection con = new SqlConnection("Data Source=PRAVEEN-PC;Initial Catalog=jobs;Integrated Security=True");
con.Open ();
SqlCommand cmd = new SqlCommand ("SELECT * FROM a3 WHERE '"+strlocation +"'LIKE[Location]");
oned_gk
All-Star
36074 Points
7361 Posts
Re: how to use chkboxlist...........
Dec 07, 2012 07:39 AM|LINK
<form id="form1" runat="server"> <asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="Location" DataValueField="Location"> </asp:CheckBoxList> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TESTConnectionString %>" SelectCommand="SELECT DISTINCT [Location] FROM [a3] WHERE ([Location] IS NOT NULL) ORDER BY [Location]"> </asp:SqlDataSource> <asp:HiddenField ID="HiddenField1" runat="server" /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="JobId" DataSourceID="SqlDataSource2"> <Columns> <asp:BoundField DataField="JobId" HeaderText="JobId" InsertVisible="False" ReadOnly="True" SortExpression="JobId" /> <asp:BoundField DataField="Position" HeaderText="Position" SortExpression="Position" /> <asp:BoundField DataField="Company" HeaderText="Company" SortExpression="Company" /> <asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" /> <asp:BoundField DataField="Experience" HeaderText="Experience" SortExpression="Experience" /> <asp:BoundField DataField="Information" HeaderText="Information" SortExpression="Information" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:TESTConnectionString %>" SelectCommand="SELECT * FROM [a3] WHERE (@Location LIKE '%' + [Location] + '%')"> <SelectParameters> <asp:ControlParameter ControlID="HiddenField1" Name="Location" PropertyName="Value" Type="String" /> </SelectParameters> </asp:SqlDataSource> </form>protected void Page_Load(object sender, EventArgs e) { HiddenField1.Value = ""; foreach (ListItem li in CheckBoxList1.Items) { if (li.Selected == true) { HiddenField1.Value = HiddenField1.Value + "," + li.Text; } } }This will work, configure the connection string
Suwandi - Non Graduate Programmer
dn631
Member
6 Points
39 Posts
Re: how to use chkboxlist...........
Dec 08, 2012 04:46 AM|LINK
can you please tell how to bind this to gridview