. Aspx
<Asp: repeater id = "repeater1" runat = "server" enableviewstate = "false">
<Itemtemplate>
<Table width = "100%" cellspacing = "0" cellpadding = "0">
<Tr>
<TD width = 25%> <% # databinder. eval (container. dataitem, "employeeid") %> </TD>
<TD width = 25%> <% # databinder. eval (container. dataitem, "firstname") %> </TD>
<TD width = 25%> <% # databinder. eval (container. dataitem, "lastname") %> </TD>
<TD width = 25%> <% # databinder. eval (container. dataitem, "title") %> </TD>
</Tr>
</Table>
</Itemtemplate>
<Headertemplate>
<Table width = "100%" cellspacing = "0" cellpadding = "0">
<Tr>
<TD width = 25%>
<Asp: linkbutton id = "lnkemployeeid" runat = "server" onclick = "sortemployeeidclick"> employeeid </ASP: linkbutton>
</TD>
<TD width = 25%>
<Asp: linkbutton id = "lnkfirstname" runat = "server" onclick = "sortfirstnameclick"> firstname </ASP: linkbutton>
</TD>
<TD width = 25%>
<Asp: linkbutton id = "lnklastname" runat = "server" onclick = "sortlastnameclick"> lastname </ASP: linkbutton>
</TD>
<TD width = 25%>
<Asp: linkbutton id = "lnktitle" runat = "server" onclick = "sorttitleclick"> title </ASP: linkbutton>
</TD>
</Tr>
</Table>
</Headertemplate>
</ASP: repeater>
VB. NET
Dim sortfield as string
Dim myconnection as sqlconnection
Dim myda as sqldataadapter
Dim ds as Dataset
Dim strconn as string
Dim sqlstmt as string = "select * from employees"
Private sub page_load (byval sender as system. Object, byval e as system. eventargs) handles mybase. Load
'Put user code to initialize the page here
Binddata ()
End sub 'page _ load
Sub binddata ()
Strconn = "Server = localhost; uid = sa; Password =; database = northwind ;"
Myconnection = new sqlconnection (strconn)
Myda = new sqldataadapter (sqlstmt, myconnection)
DS = new dataset
Myda. Fill (DS, "alltables ")
Repeater1.datasource = DS
Repeater1.databind ()
End sub 'binddata
Sub sortdata (byval sortexpression as string)
If viewstate ("sortorder") is nothing then
Viewstate ("sortorder") = "ASC"
Else
If viewstate ("sortorder"). tostring () = "ASC" then
Viewstate ("sortorder") = "DESC"
Else
Viewstate ("sortorder") = "ASC"
End if
End if
Sqlstmt = sqlstmt + "order by" + sortexpression. tostring () + "" + viewstate ("sortorder ")
Binddata ()
End sub 'sortdata
Protected sub sortemployeeidclick (byval sender as object, byval e as eventargs)
Sortfield = "employeeid"
Sortdata (sortfield)
End sub 'sortemployeeidclick
Protected sub sortfirstnameclick (byval sender as object, byval e as eventargs)
Sortfield = "firstname"
Sortdata (sortfield)
End sub 'sortfirstnameclick
Protected sub sortlastnameclick (byval sender as object, byval e as eventargs)
Sortfield = "lastname"
Sortdata (sortfield)
End sub 'sortlastnameclick
Protected sub sorttitleclick (byval sender as object, byval e as eventargs)
Sortfield = "title"
Sortdata (sortfield)
End sub 'sorttitleclick
C #
String sortfield;
Sqlconnection myconnection;
Sqldataadapter myda;
Dataset Ds;
String strconn;
String sqlstmt = "select * from employees ";
Private void page_load (Object sender, system. eventargs E)
{
// Put user code to initialize the page here
Binddata ();
}
Void binddata ()
{
Strconn = "Server = localhost; uid = sa; Password =; database = northwind ;";
Myconnection = new sqlconnection (strconn );
Myda = new sqldataadapter (sqlstmt, myconnection );
DS = new dataset ();
Myda. Fill (DS, "alltables ");
Repeater1.datasource = Ds;
Repeater1.databind ();
}
Void sortdata (string sortexpression)
{
If (viewstate ["sortorder"] = NULL)
{
Viewstate ["sortorder"] = "ASC ";
}
Else if (viewstate ["sortorder"]. tostring () = "ASC ")
{
Viewstate ["sortorder"] = "DESC ";
}
Else
{
Viewstate ["sortorder"] = "ASC ";
}
Sqlstmt = sqlstmt + "order by" + sortexpression. tostring () + "" + viewstate ["sortorder"];
Binddata ();
}
Protected void sortemployeeidclick (Object sender, eventargs E)
{
Sortfield = "employeeid ";
Sortdata (sortfield );
}
Protected void sortfirstnameclick (Object sender, eventargs E)
{
Sortfield = "firstname ";
Sortdata (sortfield );
}
Protected void sortlastnameclick (Object sender, eventargs E)
{
Sortfield = "lastname ";
Sortdata (sortfield );
}
Protected void sorttitleclick (Object sender, eventargs E)
{
Sortfield = "title ";
Sortdata (sortfield );
}