DataList控件是不是不能嵌套使用??
DataList控件是不是不能嵌套使用???如果想嵌套使用,各位高手有好方法吗??
回复 2# cyyu_ryh 的帖子
前台代码: <asp:DataList ID="dlnewssort" runat="server">
<ItemTemplate>
<table style="width: 750px; height: 150px">
<tr>
<td style="width: 600px; height:25px">
<asp:Label ID="lblnewssortname" runat="server" Text=""><%#Eval("newssortname") %></asp:Label></td>
<td style="width:150px; height:25px">
<asp:Label ID="Label5" runat="server" Text=""><a href="Default.aspx?newssortid=<%#Eval("newssortID") %>">more</a></asp:Label></td>
</tr>
<tr>
<td colspan="2" style="width: 750px; height:125px; vertical-align: text-top;">
<asp:DataList ID="dlnews2" runat="server">
<ItemTemplate>
<table style="width: 740px">
<tr>
<td style="width: 400px; height:20px">
·<asp:Label ID="lblnewstitle1" runat="server" Text=""><a href="Default.aspx?newsid=<%#Eval("newsID") %>"><%#Eval("newstitle") %></a></asp:Label></td>
<td style="width: 100px; height:20px">
<asp:Label ID="lblnewstime1" runat="server" Text=""><%#Eval("newstime") %></asp:Label></td>
<td style="width: 120px; height:20px">
<asp:Label ID="lblnewsauthor1" runat="server" Text=""><%#Eval("newsauthor") %></asp:Label></td>
<td style="width: 130px; height:20px">
<asp:Label ID="lblnewssource1" runat="server" Text=""><%#Eval("newssource") %></asp:Label></td>
</tr>
</table>
</ItemTemplate>
</asp:DataList></td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
后台代码:
private void dlnews2databind()
{
string sqlstr = Convert.ToString(ConfigurationManager.ConnectionStrings["sqlserver"]);
SqlConnection conn = new SqlConnection(sqlstr);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from news order by newstime desc", conn);
DataSet ds = new DataSet();
da.Fill(ds, "news2");
dlnews2.DataSource = ds;
dlnews2.DataBind();
}
private void dlnewssortdatabind()
{
string sqlstr = Convert.ToString(ConfigurationManager.ConnectionStrings["sqlserver"]);
SqlConnection conn = new SqlConnection(sqlstr);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from newssort", conn);
DataSet ds = new DataSet();
da.Fill(ds, "newssort");
dlnewssort.DataSource = ds;
dlnewssort.DataBind();
}
为什么会 出现这种错误:
编译器错误信息: CS0103: 当前上下文中不存在名称“dlnews2”