how to add sorting function in repeater in asp 2.0?

℡╲_俬逩灬. 提交于 2019-12-20 15:25:57

问题


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>


来源:https://stackoverflow.com/questions/8820406/how-to-add-sorting-function-in-repeater-in-asp-2-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!