求助!datalist嵌套datalist的问题 30
我有一个sql数据表,包含主题和日期字段,我想用datalist嵌套的方式实现当天日期下显示所有主题,我的代码如下:<scriptrunat="server">Prote...
我有一个sql数据表,包含主题和日期字段,我想用datalist嵌套的方式实现当天日期下显示所有主题,我的代码如下:
<script runat="server">
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Not Page.IsPostBack Then
Dim sqlstr As String
Dim lstr As String
Dim con As New SqlConnection("......")
sqlstr="SELECT distinct Convert(VARCHAR(10),riqi,120) AS duanri2 FROM table1"
Dim da3 As New SqlDataAdapter(sqlstr,con)
Dim ds3 As New System.Data.DataSet
da3.Fill(ds3, "table1")
DataList2.DataSource = ds3.Tables("table1").DefaultView
DataList2.DataBind()
Dim i As Integer
For i = 0 To DataList2.Items.Count - 1
Dim Riqi_date As System.Web.UI.WebControls.Label = DataList2.Items(i).FindControl("lbid")
Dim dlsC As System.Web.UI.WebControls.DataList = DataList2.Items(i).FindControl("DataList1")
lstr="SELECT zhuti,riqi FROM table1 WHERE Convert(VARCHAR(10),riqi,120) = '"& Riqi_date.text &"' ORDER BY riqi DESC"
Dim da2 As New SqlDataAdapter(lstr,con)
Dim ds2 As New System.Data.DataSet
da2.Fill(ds2, "table1")
dlsC.DataSource = ds2.Tables("table1").DefaultView
dlsC.DataBind()
Next
End If
End Sub
</script>
<form runat="server">
<asp:DataList id="DataList2" runat="server">
<ItemTemplate>
<div style="background-color:#edede3">
<asp:Label ID=lbid Runat=server text='<%# DataBinder.Eval(Container.DataItem,"duanri2")%>'>
</asp:Label> </div>
<asp:DataList id="DataList1" runat="server">
<Itemtemplate>
<%# Eval("zhuti")%> <%# DataBinder.Eval(Container.DataItem,"riqi")%>
</Itemtemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>
</form>
我测试后发现只有日期记录,而没有每个日期下的主题记录,是什么问题?恳请各位老师帮忙看看!谢谢! 展开
<script runat="server">
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Not Page.IsPostBack Then
Dim sqlstr As String
Dim lstr As String
Dim con As New SqlConnection("......")
sqlstr="SELECT distinct Convert(VARCHAR(10),riqi,120) AS duanri2 FROM table1"
Dim da3 As New SqlDataAdapter(sqlstr,con)
Dim ds3 As New System.Data.DataSet
da3.Fill(ds3, "table1")
DataList2.DataSource = ds3.Tables("table1").DefaultView
DataList2.DataBind()
Dim i As Integer
For i = 0 To DataList2.Items.Count - 1
Dim Riqi_date As System.Web.UI.WebControls.Label = DataList2.Items(i).FindControl("lbid")
Dim dlsC As System.Web.UI.WebControls.DataList = DataList2.Items(i).FindControl("DataList1")
lstr="SELECT zhuti,riqi FROM table1 WHERE Convert(VARCHAR(10),riqi,120) = '"& Riqi_date.text &"' ORDER BY riqi DESC"
Dim da2 As New SqlDataAdapter(lstr,con)
Dim ds2 As New System.Data.DataSet
da2.Fill(ds2, "table1")
dlsC.DataSource = ds2.Tables("table1").DefaultView
dlsC.DataBind()
Next
End If
End Sub
</script>
<form runat="server">
<asp:DataList id="DataList2" runat="server">
<ItemTemplate>
<div style="background-color:#edede3">
<asp:Label ID=lbid Runat=server text='<%# DataBinder.Eval(Container.DataItem,"duanri2")%>'>
</asp:Label> </div>
<asp:DataList id="DataList1" runat="server">
<Itemtemplate>
<%# Eval("zhuti")%> <%# DataBinder.Eval(Container.DataItem,"riqi")%>
</Itemtemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>
</form>
我测试后发现只有日期记录,而没有每个日期下的主题记录,是什么问题?恳请各位老师帮忙看看!谢谢! 展开
3个回答
展开全部
你可以加我 我发给你关于嵌套的例子 一看就明白了 呵呵
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
一般这写问题 去51aspx上找找看有没有案例 这麼问一般能难解释的清楚
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询