We Recommend

Accelerated C# 2008 Accelerated C# 2008
This book is both a rapid tutorial and a permanent reference. You’ll quickly master C# syntax while learning how the CLR simplifies many programming tasks. You’ll also learn best practices that ensure your code will be efficient, reusable, and robust. Why spend months or years discovering the best ways to design and code C# when this book will show you how to do things the right way, right from the start?


Posted By

krisdb on 07/10/08


Tagged

c-sharp


Versions (?)


repeater


Published in: C# 


  1. <asp:Repeater ID="rptItems" runat="server" OnItemDataBound="rptItems_DataBound">
  2. <ItemTemplate>
  3. <div><asp:Literal runat="server" ID="litName" /></div>
  4. <div><%# Eval("Name") %></div>
  5. </ItemTemplate>
  6. <AlternatingItemTemplate>
  7. </AlternatingItemTemplate>
  8. </asp:Repeater>
  9.  
  10. protected void Page_Load(object sender, EventArgs e)
  11. {
  12. DateTable dtResults = new DataTable();
  13.  
  14. //limit results
  15. if (intMaxResults > 0)
  16. {
  17. PagedDataSource objPds = new PagedDataSource();
  18. objPds.DataSource = dtResults.DefaultView;
  19. objPds.AllowPaging = true;
  20. objPds.PageSize = mintMaxItems;
  21. objPds.CurrentPageIndex = 0;
  22. rptItems.DataSource = objPds;
  23. rptItems.DataBind();
  24. }
  25. //bind all results
  26. else
  27. {
  28. rptItems.DataSource = dtResults;
  29. rptItems.DataBind();
  30. }
  31. }
  32.  
  33. protected void rptItems_DataBound(Object Sender, RepeaterItemEventArgs e)
  34. {
  35. if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
  36. {
  37. DataRowView drv = (DataRowView)e.Item.DataItem;
  38.  
  39. string strName = drv["Name"].ToString();
  40.  
  41. ((Literal)e.Item.FindControl("litName")).Text = strName;
  42. }
  43. }

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: krisdb on July 22, 2008

You need to login to post a comment.