<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient"
%>
<HTML>
<HEAD>
<title>Sorting in DataList</title>
<script
language=vb runat=server>
Private Sub
Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
SortDataList("stor_id " & cboSortType.SelectedItem.Value)
lblStatus.Text = "Currently Sorted on StoreID: " &
cboSortType.SelectedItem.Text
End Sub
Public Sub
SortStoreID(ByVal s As Object, ByVal e As EventArgs)
SortDataList("stor_id
" & cboSortType.SelectedItem.Value)
lblStatus.Text = "Currently Sorted on StoreID: " &
cboSortType.SelectedItem.Text
End Sub
Public Sub
SortStoreName(ByVal s As Object, ByVal e As EventArgs)
SortDataList("stor_name " &
cboSortType.SelectedItem.Value)
lblStatus.Text = "Currently Sorted on Store Name: " &
cboSortType.SelectedItem.Text
End Sub
Public Sub
SortStoreAddress(ByVal s As Object, ByVal e As EventArgs)
SortDataList("stor_address
" & cboSortType.SelectedItem.Value)
lblStatus.Text = "Currently Sorted on Store Address: " &
cboSortType.SelectedItem.Text
End Sub
Public Sub
SortStoreCity(ByVal s As Object, ByVal e As EventArgs)
SortDataList("city
" & cboSortType.SelectedItem.Value)
lblStatus.Text = "Currently Sorted on City: " &
cboSortType.SelectedItem.Text
End Sub
Public Sub
SortStoreState(ByVal s As Object, ByVal e As EventArgs)
SortDataList("state " & cboSortType.SelectedItem.Value)
lblStatus.Text = "Currently Sorted on State: " &
cboSortType.SelectedItem.Text
End Sub
Private Sub
SortDataList(ByVal strSort As String)
Dim objConn
As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim objCmd
As New SqlDataAdapter("exec sp_stores_sel", objConn)
Dim objDS
As New DataSet()
Dim objDT
As New DataTable()
Dim objDV
As New DataView()
objCmd.Fill(objDS)
objDT =
objDS.Tables(0)
objDV =
objDS.Tables(0).DefaultView
objDV.Sort
= strSort
dList.DataSource = objDV
dList.DataBind()
objConn.Close()
End Sub
</script>
</HEAD>
<body
style="font: 10pt verdana">
<form
id="Form1" method="post" runat="server">
<a
name="this"></a>
<h2
align="center">Sorting in DataList</h2>
<asp:DataList
ID="dList" Runat="server" Width="100%"
ItemStyle-BackColor="Beige"
ItemStyle-Font-Name="Verdana"
BorderWidth="1"
HeaderStyle-Font-Name="Verdana">
<HeaderTemplate>
<table
width="100%" style="font: 10pt verdana" cellpadding=0
cellspacing=0>
<tr
style="background-color:DFA894">
<th
align=left><a href="datalist.aspx#this" onserverclick="SortStoreID"
runat="server">Store ID</a></th>
<th
align=left><a href="datalist.aspx#this"
onserverclick="SortStoreName" runat="server">Name</a></th>
<th
align=left><a href="datalist.aspx#this"
onserverclick="SortStoreAddress"
runat="server">Address</a></th>
<th
align=left><a href="datalist.aspx#this"
onserverclick="SortStoreCity"
runat="server">City</a></th>
<th
align=left><a href="datalist.aspx#this"
onserverclick="SortStoreState"
runat="server">State</a></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr
style="background-color:#f5f5dc">
<td><%#
DataBinder.Eval(Container.DataItem, "stor_id") %></td>
<td><%#
DataBinder.Eval(Container.DataItem, "stor_name") %></td>
<td><%#
DataBinder.Eval(Container.DataItem, "stor_address") %></td>
<td><%#
DataBinder.Eval(Container.DataItem, "city") %></td>
<td><%#
DataBinder.Eval(Container.DataItem, "state") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
<asp:label
text="Sort Type:"
Runat="server"
Font-Name="verdana"
Font-Size="10pt"
id=Label1
/>
<asp:DropDownList
ID="cboSortType"
Runat="server"
Font-Name="verdana">
<asp:ListItem
Value="asc">Ascending</asp:ListItem>
<asp:ListItem
Value="desc">Descending</asp:ListItem>
</asp:DropDownList>
<asp:label
text="Currently Sorted On:"
ID="lblStatus"
Runat="server"
Font-Name="verdana"
Font-Size="10pt"
/>
</form>
</body>
</HTML>
Send your comments to das@aspalliance.com
Back to Article list