How to Use Repeater in ASP.NET?

  • Thread starter Thread starter KrisFrosz133
  • Start date Start date
K

KrisFrosz133

Guest
I'm using Visual Studio 2008 and I'm trying to build a prototype video game website. For one page, I want it to have a function where users can click any of the 26 alphabets and the page will list down all games that start with that letter (So if you click A, then all games start with the letter A will appear).

I've build one table from the database called Games and so how can I incorporate this to the page using repeaters? And how can make the alphabetical function to work?

I've used VB and ASP.NET before but I'm still not used to the overall system. Any help will be greatly appreciated.
 
I wrote this in C#, but it should be easy to convert over ;). The only thing to note is that I have a database called ProgrammingExamples, with a table called User_Files with a column called "Title". I take a distinct collection of that first letter in SQL, zip through it in C#'s repeater, and use that VERY confusing DataBinder.Eval() function.


<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<HeaderTemplate>
<div>Select a letter:</div>
<div>
</HeaderTemplate>
<ItemTemplate>
<div style="float:left; padding:2px 5px; margin: 0 5px 0 0;"><asp:HyperLink ID="lnkGo" runat="server" NavigateUrl='<%# "~/Game.aspx?alpha=" + DataBinder.Eval(Container.DataItem, "alpha") %>' Text='<%# DataBinder.Eval(Container.DataItem, "alpha") %>' /></div>
</ItemTemplate>
<FooterTemplate>
<div style="clear:both;height:1px;padding:0;margin:0"></div>
</div>
<div>Footer image?</div>
</FooterTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ExamplesDB %>"
SelectCommand="SELECT DISTINCT LEFT(Title, 1) AS alpha, COUNT(DISTINCT LEFT(Title, 1)) AS total
FROM User_Files
GROUP BY LEFT(Title, 1)
ORDER BY alpha">
</asp:SqlDataSource>
 
Back
Top