Sorting with repeater

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span style="border-collapse:collapse; color:#333333; font-family:Lucida Grande,Verdana,Arial,sans-serif; font-size:13px
<span style="font-family:Verdana; font-size:x-small .aspx
<span style="font-family:Verdana; font-size:xx-small <asp:Repeater ID="Repeater1" Runat=" http://dotnetslackers.com/SQL/re-29474_Sample_Code_Bidirectional_Sorting_in_ASP_NET_Repeater_control.aspx#" target="_blank" style=" <span style="color:#0000c8!important; font-weight:inherit!important; font-size:inherit!important <span style=" server "
EnableViewState="False <br/>
<ItemTemplate><br/>
<table width="100%" cellspacing="0" cellpadding="0 <br/>
<tr><br/>
<td width=25%><%# DataBinder.Eval(Container.DataItem, "Employeeid") %></td><br/>
<td width=25% ><%# DataBinder.Eval(Container.DataItem, "FirstName") %></td><br/>
<td width=25% ><%# DataBinder.Eval(Container.DataItem, "LastName") %></td><br/>
<td width=25% ><%# DataBinder.Eval(Container.DataItem, "Title") %></td><br/>
</tr><br/>
</table><br/>
</ItemTemplate><br/>
<HeaderTemplate><br/>
<table width="100%" cellspacing="0" cellpadding="0 <br/>
<tr><br/>
<td width=25%><br/>
<asp:LinkButton ID="lnkEmployeeid" Runat="server" OnClick="SortEmployeeIdClick Employeeid</asp:LinkButton><br/>
</td><br/>
<td width=25%><br/>
<asp:LinkButton ID="lnkFirstName" Runat="server" OnClick="SortFirstNameClick FirstName</asp:LinkButton><br/>
</td><br/>
<td width=25%><br/>
<asp:LinkButton ID="lnkLastName" Runat="server" OnClick="SortLastNameClick LastName</asp:LinkButton><br/>
</td><br/>
<td width=25% ><br/>
<asp:LinkButton ID="lnkTitle" Runat="server" OnClick="SortTitleClick Title</asp:LinkButton><br/>
</td><br/>
</tr><br/>
</table><br/>
</HeaderTemplate><br/>
</asp:Repeater><br/>

<span style="font-family:Verdana; font-size:x-small http://vb.net/" target="_blank" style="color:#336633 VB.NET <br/>
<br/>
<span style="font-size:xx-small Dim SortField As String<br/>
Dim myconnection As SqlConnection<br/>
Dim myda As SqlDataAdapter<br/>
Dim ds As DataSet<br/>
Dim strConn As String<br/>
Dim SQLStmt As String = "Select * from Employees "
<span style="font-family:Verdana; font-size:xx-small Private Sub Page_Load(ByVal sender As http://dotnetslackers.com/SQL/re-29474_Sample_Code_Bidirectional_Sorting_in_ASP_NET_Repeater_control.aspx#" target="_blank" style=" <span style="color:#0000c8!important; font-weight:inherit!important; font-size:inherit!important <span style=" System .Object,
ByVal e As System.EventArgs) Handles MyBase.Load<br/>
Put user code to initialize the page here<br/>
BindData()<br/>
End Sub Page_Load
<span style="font-family:Verdana; font-size:xx-small Sub BindData()<br/>
strConn = "Server=localhost;uid=sa;password=;database=northwind;"<br/>
myconnection = New SqlConnection(strConn)<br/>
myda = New SqlDataAdapter(SQLStmt, myconnection)<br/>
ds = New DataSet<br/>
myda.Fill(ds, "AllTables")<br/>
Repeater1.DataSource = ds<br/>
Repeater1.DataBind()<br/>
End Sub BindData
<span style="font-family:Verdana; font-size:xx-small Sub SortData(ByVal SortExpression As String)<br/>
If ViewState("SortOrder") Is Nothing Then<br/>
ViewState("SortOrder") = " ASC"<br/>
Else<br/>
If ViewState("SortOrder").ToString() = " ASC" Then<br/>
ViewState("SortOrder") = " DESC"<br/>
Else<br/>
ViewState("SortOrder") = " ASC"<br/>
End If<br/>
End If<br/>
SQLStmt = SQLStmt + " ORDER BY " + SortExpression.ToString() + " " + ViewState("SortOrder")<br/>
BindData()<br/>
End Sub SortData
<span style="font-family:Verdana; font-size:xx-small Protected Sub SortEmployeeIdClick(ByVal sender As Object, ByVal e As EventArgs)<br/>
SortField = "EmployeeId"<br/>
SortData(SortField)<br/>
End Sub SortEmployeeIdClick
<span style="font-family:Verdana; font-size:xx-small Protected Sub SortFirstNameClick(ByVal sender As Object, ByVal e As EventArgs)<br/>
SortField = "FirstName"<br/>
SortData(SortField)<br/>
End Sub SortFirstNameClick
<span style="font-family:Verdana; font-size:xx-small Protected Sub SortLastNameClick(ByVal sender As Object, ByVal e As EventArgs)<br/>
SortField = "LastName"<br/>
SortData(SortField)<br/>
End Sub SortLastNameClick
<span style="font-family:Verdana; font-size:x-small <span style="font-size:xx-small Protected Sub SortTitleClick(ByVal sender As Object, ByVal e As EventArgs)<br/>
SortField = "Title"<br/>
SortData(SortField)<br/>
End Sub SortTitleClick


View the full article
 
Back
Top