<%
Sub ShowImages(ImageType,ImageClass,ImageWidth,ImageHeight,ImageCol,ImagePage,ImageContent,ShowPage)
Response.Buffer=True  response.Write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>")
set rs= Server.CreateObject("adodb.recordset")
if ImageType="rec" then
sql="SELECT * from title as a,imgbook as b WHERE b.titleID=a.titleID and b.Recomm=1"
if ImageClass<>"all" then sql=sql&" and a.ClassName='"&ImageClass&"'"
sql=sql&" order by b.genxing desc,b.ID desc"
else
sql="SELECT a.titleid,a.classname,a.[desc],a.titlename,a.titleCount,b.photos from title as a,imgbook as b where a.titleCount<>0 and b.photos=(select top 1 photos from imgbook where titleid=a.titleid order by click desc)"
if ImageClass<>"all" then sql=sql&" and a.ClassName='"&ImageClass&"'"
if ImageType="hot" then
sql=sql&" order by a.clickCount desc"
else
sql=sql&" order by a.updatetime desc"
end if
end If


rs.pagesize = ImagePage
rs.cachesize = ImagePage
rs.open sql,conn,1,1
ipagecount = rs.pagecount
If ipagecurrent > ipagecount Then ipagecurrent = ipagecount
If ipagecurrent < 1 Then ipagecurrent = 1
if ipagecount=0 then
response.write "<tr><td align='center'>没有任何符合条件的图片</td></tr>"
else
rs.absolutepage = ipagecurrent
if ShowPage="0" and ImageClass<>"all" then 
        'rs.movenext
rs.movenext
end if
i = 0
do while not rs.eof and i<ImagePage
response.Write("<tr>")
for NextID=1 to ImageCol
  if rs.eof or rs.bof then exit for %>
  <td width="<%=cint(100/ImageCol)%>%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr> 
  <td align="center"><table border="0" cellpadding="0" cellspacing="0" style="width: <%=ImageWidth%>">
  <tr>
<td style="height: <%=ImageHeight%>" align="center" bgcolor="#EEEEEE" valign="middle">
<%if not rs.eof then%>
<table width="100%"  border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="82C0CD">
      <tr>
        <td bgcolor="#FFFFFF"><a href="search.asp?classname=<%=rs("ClassName")%>&text=<%=rs("titleName")%>" onMouseOver="ShowMsg('<%=rs("Desc")%>','#FFFFFF',150);" onMouseOut="HideMsg();"><img src="UploadImages/<%=rs("photos")%>" alt="点我一下 ^_^" border="0"></a></td>
        </tr></table><%end if%></td>
  </tr><tr><td bgcolor="F6F6F6"  align="center"><a href="search.asp?classname=<%=rs("classname")%>&text=<%=rs("titleName")%>" class="black"><%=rs("titleName")%></a>[<font color="#FF0000"><%=rs("titleCount")%></font>张]
</td></tr>
<tr><td height="10"></td></tr>
</table></td><%if ImageContent=1 then%>
  <%end if%>
</tr>
</table></td>
  <%
  rs.movenext
  i=i+1
next
response.Write("</tr>")
loop
if ShowPage=1 then%>
<tr> 
<td height='20' align='center' colspan='4'>
共找到 <font color="#FF0000"><%=i%></font>/<%=rs.recordcount%>张图片 第<font color="#FF0000"><%=ipagecurrent%></font>/<%=ipagecount%>页 
<%str="?ShowContent="&ImageType&","&ImageClass&","&ImageWidth&","&ImageHeight&","&ImageCol&","&ImagePage&","&ImageContent&","&ShowPage&"&page="
if ipagecurrent>1 then
Response.Write"<a href='"&str&"1' class='red'>首页</a> "
Response.Write"<a href='"&str&ipagecurrent-1&"' class='red'>上一页</a> "
end if
if ipagecount>ipagecurrent then
Response.Write"<a href='"&str&ipagecurrent+1&"' class='red'>下一页</a> "
Response.Write" <a href='"&str&ipagecount&"' class='red'>末页</a> "
end if%></td></tr><%end if
rsclose
end if
response.Write("</table>")
End Sub
%>
请把以上ASP代码帮小弟转成C#代码,要编译通过的!谢谢!

解决方案 »

  1.   

    晕死!i = 0
    do while not rs.eof and i<ImagePage
    response.Write("<tr>")
    for NextID=1 to ImageCol
      if rs.eof or rs.bof then exit for%>
      <td width="<%=cint(100/ImageCol)%>%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr> 
      <td align="center"><table border="0" cellpadding="0" cellspacing="0" style="width: <%=ImageWidth%>">
      <tr>
    <td style="height: <%=ImageHeight%>" align="center" bgcolor="#EEEEEE" valign="middle">
    <%if not rs.eof then%>
    <table width="100%"  border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="82C0CD">
          <tr>
            <td bgcolor="#FFFFFF"><a href="search.asp?classname=<%=rs("ClassName")%>&text=<%=rs("titleName")%>" onMouseOver="ShowMsg('<%=rs("Desc")%>','#FFFFFF',150);" onMouseOut="HideMsg();"><img src="UploadImages/<%=rs("photos")%>" alt="点我一下 ^_^" border="0"></a></td>
            </tr></table><%end if%></td>
      </tr><tr><td bgcolor="F6F6F6"  align="center"><a href="search.asp?classname=<%=rs("classname")%>&text=<%=rs("titleName")%>" class="black"><%=rs("titleName")%></a>[<font color="#FF0000"><%=rs("titleCount")%></font>张]
    </td></tr>
    <tr><td height="10"></td></tr>
    </table></td><%if ImageContent=1 then%>
      <%end if%>
    </tr>
    </table></td>
      <%
      rs.movenext
      i=i+1
    next
    response.Write("</tr>")只要这一段!!!
      

  2.   

    你这个是显示图片的吧?
    你直接用datalist来显示就行了
    读取数据,然后绑定就行
      

  3.   

    我也想用控件啊,但是原先的ASP文件是调用这个SUB,在一个页面上显示可控制个数的图片,小弟我初学.NET,不知道咋办了!http://pic.myzone.cn这个页面,大家可以看一下!
      

  4.   

    英文口语:so long=goodbye...^^
      

  5.   

    使用ASP.NET(DataList)从数据库中读取图片显示在页面上,效果像桌面图标显示一样。
             图片                     图片               图片
      图片信息(动态)         图片信息(动态)      图片信息(动态)
              图片                    图片               图片
      图片信息(动态)         图片信息(动态)      图片信息(动态)
           图片                   图片                   图片
      图片信息(动态)        图片信息(动态)       图片信息(动态)
    --------------------------------------------------------------------------------
    <asp:DataList id="DataList1" runat="server" Width="100%" RepeatDirection="Horizontal" RepeatColumns="3">
    <ItemTemplate>
    <TABLE cellSpacing="0" cellPadding="0" width="100%" border="0">
    <tr>
    <td rowspan="3" align="center">
    <img src='<%# DataBinder.Eval(Container.DataItem, "Image")%>'>
    </td>
    </tr>
    </TABLE>
    </ItemTemplate>
    </asp:DataList>
    其中"Image"的Image是数据库你所要动态显示字段,存放信息如c:\meng.jgp.读取绑定就行了