I have repeater control and i am fetching records from database, so i have number of records and i want to filter my result by using dropdowns. I am using ajax. If i select first dropdown then it filter result according to first and again when i select second dropdown then it fetch result according to second only, but i want if one dropdown is already selected then on selecting second dropdown it should filter from previous dropdown result. How to do it...
My search dropdowns are in master page and among these only category dropdown is compulsory to select and result shows in result.aspx page and also my filter dropdowns are in result page.
master page code:
<asp:DropDownList ID="dd_state" runat="server" CssClass="dropdownstyle2" >
</asp:DropDownList>
<asp:TextBox ID="txt_pincode" runat="server" CssClass="dropdownstyle3" value="Pincode" Text="" onKeyUp="numericFilter(this);" maxlength="6"
onFocus="if(this.value==this.defaultValue) this.value=''; " onBlur="if(this.value=='') this.value=this.defaultValue;"></asp:TextBox>
<asp:DropDownList ID="dd_category" runat="server" CssClass="dropdownstyle4"
AutoPostBack="True" onselectedindexchanged="dd_category_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="dd_subcategory" runat="server" CssClass="dropdownstyle5" >
</asp:DropDownList>
<asp:Button ID="but_go" runat="server" Text="Go" CssClass="gobuttonstyle" OnClientClick="return validate();"
onclick="but_go_Click"/>
protected void but_go_Click(object sender, EventArgs e)
{
Session["country"] = 1;
Session["state"] = dd_state.SelectedValue;
Session["pincode"] = txt_pincode.Text;
Session["category"] = dd_category.SelectedValue;
Session["subcategory"] = dd_subcategory.SelectedValue;
Response.Redirect("Results.aspx");
}
Result.aspx.cs
protected void BindRepeaterData()
{
con.Open();
SqlCommand cmd = new SqlCommand("sps_searchresult", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@country", 1);
cmd.Parameters.AddWithValue("@state", state);
cmd.Parameters.AddWithValue("@pincode", pincode);
cmd.Parameters.AddWithValue("@category", category);
cmd.Parameters.AddWithValue("@subcategory", subcategory);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
rep_results.DataSource = ds;
rep_results.DataBind();
con.Close();
}
ALTER PROCEDURE [dbo].[sps_searchresult]
@country nvarchar(10),
@state nvarchar(20),
@pincode nvarchar(10),
@category nvarchar(10),
@subcategory nvarchar(20)
AS
BEGIN
if(@state='Select State' and @pincode='Pincode' and @subcategory='Select Sub-Category')
begin
select r.*, s.s_name, CASE iam WHEN 1 THEN 'Professional/Business' ELSE 'Individual' End as iamdetail, substring(description,1,200)+'...' AS shortdescription, substring(title,1,40) AS shorttitle from tbl_adregister r INNER JOIN tbl_state s ON r.state = s.s_id
where country=@country and category=@category
end
if(@state='Select State' and @pincode='Pincode' and @subcategory!='Select Sub-Category')
begin
select r.*, s.s_name, CASE iam WHEN 1 THEN 'Professional/Business' ELSE 'Individual' End as iamdetail, substring(description,1,200)+'...' AS shortdescription, substring(title,1,40) AS shorttitle from tbl_adregister r INNER JOIN tbl_state s ON r.state = s.s_id
where country=@country and category=@category and subcategory=@subcategory
end
if(@state='Select State' and @pincode!='Pincode' and @subcategory='Select Sub-Category')
begin
select r.*, s.s_name, CASE iam WHEN 1 THEN 'Professional/Business' ELSE 'Individual' End as iamdetail, substring(description,1,200)+'...' AS shortdescription, substring(title,1,40) AS shorttitle from tbl_adregister r INNER JOIN tbl_state s ON r.state = s.s_id
where country=@country and category=@category and pincode=@pincode
end
if(@state='Select State' and @pincode!='Pincode' and @subcategory!='Select Sub-Category')
begin
select r.*, s.s_name, CASE iam WHEN 1 THEN 'Professional/Business' ELSE 'Individual' End as iamdetail, substring(description,1,200)+'...' AS shortdescription, substring(title,1,40) AS shorttitle from tbl_adregister r INNER JOIN tbl_state s ON r.state = s.s_id
where country=@country and category=@category and pincode=@pincode and subcategory=@subcategory
end
if(@state!='Select State' and @pincode='Pincode' and @subcategory='Select Sub-Category')
begin
select r.*, s.s_name, CASE iam WHEN 1 THEN 'Professional/Business' ELSE 'Individual' End as iamdetail, substring(description,1,200)+'...' AS shortdescription, substring(title,1,40) AS shorttitle from tbl_adregister r INNER JOIN tbl_state s ON r.state = s.s_id
where country=@country and category=@category and state=@state
end
if(@state!='Select State' and @pincode='Pincode' and @subcategory!='Select Sub-Category')
begin
select r.*, s.s_name, CASE iam WHEN 1 THEN 'Professional/Business' ELSE 'Individual' End as iamdetail, substring(description,1,200)+'...' AS shortdescription, substring(title,1,40) AS shorttitle from tbl_adregister r INNER JOIN tbl_state s ON r.state = s.s_id
where country=@country and category=@category and state=@state and subcategory=@subcategory
end
if(@state!='Select State' and @pincode!='Pincode' and @subcategory='Select Sub-Category')
begin
select r.*, s.s_name, CASE iam WHEN 1 THEN 'Professional/Business' ELSE 'Individual' End as iamdetail, substring(description,1,200)+'...' AS shortdescription, substring(title,1,40) AS shorttitle from tbl_adregister r INNER JOIN tbl_state s ON r.state = s.s_id
where country=@country and category=@category and state=@state and pincode=@pincode
end
if(@state!='Select State' and @pincode!='Pincode' and @subcategory!='Select Sub-Category')
begin
select r.*, s.s_name, CASE iam WHEN 1 THEN 'Professional/Business' ELSE 'Individual' End as iamdetail, substring(description,1,200)+'...' AS shortdescription, substring(title,1,40) AS shorttitle from tbl_adregister r INNER JOIN tbl_state s ON r.state = s.s_id
where country=@country and category=@category and state=@state and pincode=@pincode and subcategory=@subcategory
end
END
filter dropdowns at result page:
<asp:DropDownList ID="dd_state" runat="server" AutoPostBack="True"
onselectedindexchanged="dd_state_SelectedIndexChanged" ></asp:DropDownList>
<br/>
<asp:DropDownList ID="dd_category" runat="server" AutoPostBack="True"
onselectedindexchanged="dd_category_SelectedIndexChanged"></asp:DropDownList>
<br/>
<asp:DropDownList ID="dd_subcategory" runat="server" AutoPostBack="True"
onselectedindexchanged="dd_subcategory_SelectedIndexChanged"></asp:DropDownList>