I m using asp 2.0, I need an requirement for sorting the repeater control. I search over the Internet but i could nt find the correct solution. If anyone knows the answer please help to solve my problem.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You need to sort the collection before binding to the repeater.
If you want to dynamically sort on post backs, sort in the event handler before re-binding to the repeater.
回答2:
This article explains how to add sort functionality to a Repeater or a DataList control. It might help to your purpose or at least as a guide.
回答3:
Finally i got the Sorting output in Repeater Control.
1.Maintaining the Static Variable;
static int count = 0;
2.In LinkButton click Event
protected void lnkreq_name_click(object sender, EventArgs e)
{
count=Convert.ToInt32(ViewState["count"].ToString());
ViewState["count"] = count;
loadRepeater("REQUEST_NAME",count);
}
3.call the Function
protected void loadRepeater(string reqname,int count)
{
//write the code to bind into Dataset
DataView dv = ds.Tables[0].DefaultView;
if (count == 0)
{
dv.Sort = reqname + " asc";
ViewState["count"] = 1;
}
else if (count == 1)
{
dv.Sort = reqname + " desc";
ViewState["count"] = 0;
}
//then bind into repeater
}
4.In Repeater
<asp:Repeater runat="server" ID="RepeaterEntry" >
<HeaderTemplate >
<table class="list_table" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<th><asp:LinkButton ID="lnkreq_name" runat="server" ForeColor="white" OnClick="lnkreq_name_click" >Request Name</asp:LinkButton></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Eval("REQUEST_NAME")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>