当前位置: 代码迷 >> ASP.NET >> ascx里如何用循环
  详细解决方案

ascx里如何用循环

热度:9748   发布时间:2013-02-25 00:00:00.0
ascx里怎么用循环啊
我还是个小菜鸟,有个问题,想把新闻列表写在ascx出来,然后在aspx里引用
这是我写的ascx,一运行提示“mylist为定义”。
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="myas.ascx.cs" Inherits="myas1" %>

<table>
  <%
  part mypart = new part();
  string strsql = "select * from tab01";
  ArrayList mylist = mypart.selectSQL(strsql);
   
  for(int i=0;i<mylist.Count;i++){ %>
  <tr>
  <td style="width: 409px">
  <asp:Label ID="Label1" runat="server" Text="Label" Width="407px"><a href="#"><%=mylist[i]%></a></asp:Label></td>
  </tr>
  <%} %>
</table>

------解决方案--------------------------------------------------------
你这是asp的写法,建议你用.net的写法,在myas.ascx.cs文件中写代码
<%#Eval()#%>
------解决方案--------------------------------------------------------
Repeater可以实现
------解决方案--------------------------------------------------------
把 <asp:Label ID="Label1" runat="server" Text="Label" Width="407px"> </asp:Label>
去掉就行...