我有一个中继器控件,在其中我显示数据库中的值,我需要使用链接按钮进行排序
这是我的代码
<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>
和
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DB_CGTPO_DEVEConnectionString %>"
SelectCommand="SELECT * FROM [region_test] ORDER BY [code], [regon_name]"></asp:SqlDataSource>
有什么建议吗?
快速地,您可以在这些lihn按钮中添加一个事件并更改select命令,类似于以下命令:
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可以为每个按钮添加一个事件,并通过命令应用顺序!此链接显示了一种很好的方法,也可以使用中继器(使用ViewState保存订单状态):http://weblogs.asp.net/sushilasb/archive/2004/10/09/240110.aspx
[]s