I have Gridview & I want to sort it based on selection value from dropdown list.
For Example,
I have Dropdown List :::
<asp:dropdownlist id="drpsort" runat="server">
<Listitem> Won </Listitem>
<Listitem> Lost </Listitem>
<Listitem> On Hold </Listitem>
</asp:dropdownlist>
So, When any1 select Won, Gridview sorts By Won & like that for all...
1. if your selecting any value from drop down just send a query to database and sort it there accroding to selected value and rebind the grid.
2. there should be one more dropdown containing the direction of sorting (desc and asc)
Please let me know if it helps
Yeah, It will...
But is there any easy method to do it ??? I mean for wat ur saying, I will need to do coding for all values & in my case, I have atleast 20-30 values in different dropdowns...
jeeten09
Member
122 Points
150 Posts
Sort Gridview Data Based On Selection Value from Dropdown List...
Mar 25, 2012 03:48 PM|LINK
Hello All,
I have Gridview & I want to sort it based on selection value from dropdown list.
For Example,
I have Dropdown List :::
<asp:dropdownlist id="drpsort" runat="server">
<Listitem> Won </Listitem>
<Listitem> Lost </Listitem>
<Listitem> On Hold </Listitem>
</asp:dropdownlist>
So, When any1 select Won, Gridview sorts By Won & like that for all...
Please help me...
Thank You...
paritoshmmec
Participant
1555 Points
304 Posts
Re: Sort Gridview Data Based On Selection Value from Dropdown List...
Mar 25, 2012 04:04 PM|LINK
I think it should be like this:
1. if your selecting any value from drop down just send a query to database and sort it there accroding to selected value and rebind the grid.
2. there should be one more dropdown containing the direction of sorting (desc and asc)
Please let me know if it helps
Thanks and Regards,
Paritosh
jeeten09
Member
122 Points
150 Posts
Re: Sort Gridview Data Based On Selection Value from Dropdown List...
Mar 25, 2012 04:06 PM|LINK
Yeah, It will...
But is there any easy method to do it ??? I mean for wat ur saying, I will need to do coding for all values & in my case, I have atleast 20-30 values in different dropdowns...
paritoshmmec
Participant
1555 Points
304 Posts
Re: Sort Gridview Data Based On Selection Value from Dropdown List...
Mar 25, 2012 04:13 PM|LINK
use this then
Thanks and Regards,
Paritosh
jeeten09
Member
122 Points
150 Posts
Re: Sort Gridview Data Based On Selection Value from Dropdown List...
Mar 25, 2012 04:16 PM|LINK
I think It will help me for sure...
Thank you...
basheerkal
Star
10672 Points
2426 Posts
Re: Sort Gridview Data Based On Selection Value from Dropdown List...
Mar 25, 2012 06:27 PM|LINK
Hope the DropDownList is populated with the Field names.
If your Gidview is GV, its DataSource is DS and your DropDownList is DDL
in SelectedIndexChanged Event of DDL put this code.( DDL's AutoPostback is to be set as true)
DS.SelectCommand=" SELECT * From YourTable ORDER BY " + DDL.SelectedItem.Text" ;
GV. DataBind();
B
(Talk less..Work more)