Reputation: 11000
I have a repeater control in which i am showing values from database and i need to do sorting using a link button
Here is my code
<div class="demo">
<ul id="sortable1" class="connectedSortable" style="border-style: groove; border-width: inherit;border-color: #D4D0C8; height: 100%; width: 170px;">
<asp:LinkButton ID="LinkButton2" runat="server" onclick="LinkButton2_Click" >LinkButton</asp:LinkButton>
<asp:Repeater ID="rpt1" runat="server" DataSourceID="sqlDataSource1">
<ItemTemplate>
<li class="ui-state-default" >
<%# DataBinder.Eval(Container.DataItem, "code") %>
<%# DataBinder.Eval(Container.DataItem, "regon_name") %>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</div>
and
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DB_CGTPO_DEVEConnectionString %>"
SelectCommand="SELECT * FROM [region_test] ORDER BY [code], [regon_name]"></asp:SqlDataSource>
Any suggestions?
Upvotes: 0
Views: 2304
Reputation: 38598
rapidly, you could add an event in these likn buttons and change the select command, something like this:
public void LinkButton2_Click(object sender, EventArgs e)
{
//set the new select command with a ordery by
SqlDataSource1.SelectCommand = "SELECT * FROM [region_test] ORDER BY [regon_name]";
//refresh the repeater
rpt1.DataBind();
}
Yo can add an event for every button and apply the order by command! This link shows a nice way to do it as well with repeaters (using ViewState to save the state of order by): http://weblogs.asp.net/sushilasb/archive/2004/10/09/240110.aspx
[]s
Upvotes: 1