开发者

How to go about writing this classic asp in asp.net

开发者 https://www.devze.com 2022-12-27 03:36 出处:网络
I am stuck in converting this snipped to asp.net. set RSLinksCat = conn.Execute(\"select linkscat.id, linkscat.category from linkscat, contentlinks, links where contentlinks.linksid = links.id and c

I am stuck in converting this snipped to asp.net.

set RSLinksCat = conn.Execute("select linkscat.id, linkscat.category from linkscat, contentlinks, links where contentlinks.linksid = links.id and contentlinks.contentid = " & contentid & " and links.linkscatid = linkscat.id order by linkscat.category")


<%if not RSLinksCat.EOF then%><h1>Links</h1>
<br />
<%开发者_运维技巧do while not RSLinksCat.EOF%>
<%set RSLinks = conn.Execute("select * from links where linkscatid = " & RSLinksCat("id") & "")%>

 <strong><%=RSlinkscat("category")%><strong>
    <ul>
                    <%do while not RSlinks.EOF%>
                    <li>
                      <a href = "http://<%=RSLinks("url")%>" target="_blank"><%=RSlinks("description")%></a>
                    </li>
                     <%RSLinks.MoveNext
                    loop%>
    </ul>
                 <%RSLinksCat.MoveNext
                 loop%>
<br />
<%end if%><%conn.close%>

I'm not sure where to start. Can anyone recommend the correct approach i.e sqldatareaders or repeaters or arrays or sqldatareaders or? VB code samples most welcome.

Thanks


If you came from the ASP Classic world, you may find ASP.net MVC easy to deal with. No need to learn what server control do you need or how to deal with the ViewState.

Converted code, using LINQ as DAL:

<h1>Links</h1>
<br />
<% For each linkcat in Model%>
<strong><%=linkcat.category%><strong>
  <ul>
     <% For each link in linkcat.Links%>
        <li>
        <a href="http://<%=Link.url%>" target="_blank"><%=links.description%></a>
        </li>
    <% Next %>
    </ul>
<br />
<% Next %>


Phil

Start from give some small time and find a Dal Data access layer, a communication way with your database, like subsonic 2.3, or linq to sql.

Then if you see any example on this DALs and play few days with it, the rest will be very easy.

Also you need to move from asp to asp.net thinking that asp.net is something different, and not because both have the asp, means something. I mean that you do not just port the code from one to the other... needs more to get out the thesaurus of asp.net.


Please look at the DataList, Repeater, or similar Server Control samples to see how to implement what you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消