how to add sorting function in repeater in asp 2.0?

前端 未结 3 1445
甜味超标
甜味超标 2021-02-06 17:10

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

相关标签:
3条回答
  • 2021-02-06 17:48

    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.

    0 讨论(0)
  • 2021-02-06 17:49

    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.

    0 讨论(0)
  • 2021-02-06 18:01

    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>
    
    0 讨论(0)
提交回复
热议问题