Table Name : JOBTABLE
Fields : JobId, Position, Company, Location, Experience, Information
ASPX
Location <asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="Location" DataValueField="Location" RepeatDirection="Horizontal" RepeatLayout="Flow"> </asp:CheckBoxList> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TESTConnectionString %>" SelectCommand="SELECT DISTINCT [Location] FROM [JOBTABLE] 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 [JOBTABLE] WHERE (@Location LIKE '%' + [Location] + '%')"> <SelectParameters> <asp:ControlParameter ControlID="HiddenField1" Name="Location" PropertyName="Value" Type="String" /> </SelectParameters> </asp:SqlDataSource>
C#
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; } } }
No comments:
Post a Comment