Asp.net嵌套
asp.net实现了代码的后置,页面与后台代码分开,比起asp逻辑清晰的很多,不过我感觉有时候为了方便,必要的时候实现内嵌的方式还是很不错的,今天在做一个产品根据类型轮换显示的时候用到了内嵌,方便了很多
首先要根据类型的数量循环出几个表格出来,然后根据类型循环显示显示产品,使用内嵌一步到位,代码如下
View Code
1 <%
2
3 System.Data.DataSet dsType = ProTypeManager.GetList(8, " pid=0", " id asc");
4 for (int i = 0; i < dsType.Tables[0].Rows.Count; i++)
5 {
6 string BType = dsType.Tables[0].Rows[i]["id"].ToString();
7 System.Data.DataSet ds = ProductManager.GetList(10, " jh_btype=" + BType, " jh_id desc");
8 DataPro.DataSource = ds;
9 DataPro.DataBind();
10
11 %>
12 <%
13 if ((i + 1) != 1)
14 {
15 %>
16
17 <table border="0" cellspacing="0" cellpadding="0" id="tgcpf<%=i+1 %>" style="display:none">
18 <%}
19 else {
20 %>
21 <table border="0" cellspacing="0" cellpadding="0" id="tgcpf<%=i+1 %>" style="display:block">
22 <%
23 }
24 %>
25 <tr>
26 <td>
27 <asp:DataList ID="DataPro" runat="server" RepeatColumns="5">
28 <ItemTemplate>
29 <table border="0" cellspacing="0" cellpadding="0">
30 <tr>
31 <td width="118" height="93" align="center" valign="middle"><a href="#" target="_blank"><img src='userfiles/image/<%#Eval("jh_pic") %>' width="103" height="85" border="0" /></a></td>
32 </tr>
33 <tr>
34 <td width="118" height="22" align="center" valign="middle"><a href="#" target="_blank">产品:<%#Eval("jh_name")%></a></td>
35 </tr>
36 </table>
37 </ItemTemplate>
38 </asp:DataList>
39 </td>
40 </tr>
41 </table>
42 <%
43 }
44 %>
45
2
3 System.Data.DataSet dsType = ProTypeManager.GetList(8, " pid=0", " id asc");
4 for (int i = 0; i < dsType.Tables[0].Rows.Count; i++)
5 {
6 string BType = dsType.Tables[0].Rows[i]["id"].ToString();
7 System.Data.DataSet ds = ProductManager.GetList(10, " jh_btype=" + BType, " jh_id desc");
8 DataPro.DataSource = ds;
9 DataPro.DataBind();
10
11 %>
12 <%
13 if ((i + 1) != 1)
14 {
15 %>
16
17 <table border="0" cellspacing="0" cellpadding="0" id="tgcpf<%=i+1 %>" style="display:none">
18 <%}
19 else {
20 %>
21 <table border="0" cellspacing="0" cellpadding="0" id="tgcpf<%=i+1 %>" style="display:block">
22 <%
23 }
24 %>
25 <tr>
26 <td>
27 <asp:DataList ID="DataPro" runat="server" RepeatColumns="5">
28 <ItemTemplate>
29 <table border="0" cellspacing="0" cellpadding="0">
30 <tr>
31 <td width="118" height="93" align="center" valign="middle"><a href="#" target="_blank"><img src='userfiles/image/<%#Eval("jh_pic") %>' width="103" height="85" border="0" /></a></td>
32 </tr>
33 <tr>
34 <td width="118" height="22" align="center" valign="middle"><a href="#" target="_blank">产品:<%#Eval("jh_name")%></a></td>
35 </tr>
36 </table>
37 </ItemTemplate>
38 </asp:DataList>
39 </td>
40 </tr>
41 </table>
42 <%
43 }
44 %>
45
多思考,多创新,才是正道!