.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Repeater Control in ASP.Net

Posted By:Sasi Prabhu       Posted Date: July 29, 2011    Points: 40    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

Bind a DataSet to a Repeater Control. The Repeater control is used to display a repeated list of items that are bound to the control.
 

The Repeater control is used to display a repeated list of items that are bound to the control.

In .aspx Page :


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

The Repeater Contains 3 Templetes

HeaderTemplate  - Header of Repeater
ItemTemplate      - Content of Repeater
FooterTemplete   - Footer of Repeater


To Bind Values Through Coding

.aspx.cs

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


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend