Sample Code: Bidirectional Sorting in ASP.NET Repeater control
ASP.NET
Thread Starter: Paschal
Started:
Replies: 0

Ireland .NET Developer Alliance :: Forums » Technologies » ASP.NET » Sample Code: Bidirectional Sorting in ASP.NET Repeater control
« Previous Thread Next Thread »
   30 Oct 2004, 7:02
Paschal is not online. Last active: 21/01/2005 18:37:42 Paschal
Sample Code: Bidirectional Sorting in ASP.NET Repeater control

.aspx


 
 
 
  
  
  
  
 
 
<%# DataBinder.Eval(Container.DataItem, "Employeeid") %> <%# DataBinder.Eval(Container.DataItem, "FirstName") %> <%# DataBinder.Eval(Container.DataItem, "LastName") %> <%# DataBinder.Eval(Container.DataItem, "Title") %>

 

 
 
 
  
  
  
  
 
 

  Employeeid
  

  FirstName
  

  LastName
  

  Title
  

 


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);
}


  
  Page 1 of 1 (1 items)
Ireland .NET Developer Alliance :: Forums » Technologies » ASP.NET » Sample Code: Bidirectional Sorting in ASP.NET Repeater control

Powered by Community Server :: Forums