How would you do this, what control?

  • Thread starter Thread starter Shawn Ferguson
  • Start date Start date
S

Shawn Ferguson

I'm new to ASP.NET and CSharp, I'm making the SLOW transition from classic ASP. I am truly amazed by the robustness of the new environment. However, I ran into a small problem. Before in ASP, I would create a loop below:

do while not rs.eof
<a href="myPage.asp?ID=<%=rs("myID")%> ><%=rs("Title")%></a>
movenext
loop

But now with .NET not sure what tool to use and how to use it. Would you care to offer any advice? Thanks ahead of time.
 
Shawn,

You can do the same thing in ASP.NET. There is nothing stopping you from executing a for loop and writing to the response stream with what would be almost the same syntax (changed for the C# language, if that is what you are using on the code behind).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
I'm new to ASP.NET and CSharp, I'm making the SLOW transition from classic ASP. I am truly amazed by the robustness of the new environment. However, I ran into a small problem. Before in ASP, I would create a loop below:

do while not rs.eof
<a href="myPage.asp?ID=<%=rs("myID")%> ><%=rs("Title")%></a>
movenext
loop

But now with .NET not sure what tool to use and how to use it. Would you care to offer any advice? Thanks ahead of time.
 
There isn't a "new and improved" method of accomplishing it using the newer controls?
 
I'm new to ASP.NET and CSharp, I'm making the SLOW transition from classic ASP. I am truly amazed by the robustness of the new environment. However, I ran into a small problem. Before in ASP, I would create a loop below:

do while not rs.eof
<a href="myPage.asp?ID=<%=rs("myID")%> ><%=rs("Title")%></a>
movenext
loop

But now with .NET not sure what tool to use and how to use it. Would you care to offer any advice? Thanks ahead of time.

One possible solution is the RepeaterControl (<asp:Repeater
Id="Myrepeater" />). You basically create the control and a template,
and in your .cs code behind fine (definately go with the code behind
route), you would so something like this:

Myrepeater.DataSource = rs; // Where rs is an IDataReader, such as
SqlDataReader for Sql server

And you're done! Mostly..
 
Shawn,
Not sure if this is really a "C# Language" group post, it probably ought to
have been in the ASP.NET group. As Nick indicated, you can certainly use the
same style of loop and Response.Write 's as classic ASP.

However, ASP.NET offers controls such as the Repeater that make this
effortless.

Take a look at the QUICKSTARTS:

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/default.aspx

This is the best place to start when you are a "n00b" (which we all were,
once...)
Peter
 
You could use a Repeater control, and then create an ItemTemplate for the repeater and populate it using a data reader (don't load the whole data set, there is no point here unless you need to use it elsewhere).
 
Back
Top