读书人

repeater嵌套有关问题(asp.net)

发布时间: 2012-01-30 21:15:58 作者: rapoo

repeater嵌套问题(asp.net)
使用repeater嵌套,报错为 “服务器标记的格式不正确。”,不知正确的如何写


'################ Begin: repeater.aspx.vb ##########################
Imports System.Data
Imports System.Data.SqlClient
Imports system.configuration


Partial Class repeater
Inherits System.Web.UI.Page

Public conn As New SqlConnection()
Public Const ConnectionString As String = "Data Source=(local); Initial Catalog=Cla; UId=sa; Pwd=password "
Public cmd As SqlCommand
Public sql As String

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
conn.ConnectionString = ConfigurationManager.ConnectionStrings( "DSN_J_Cla ").ConnectionString

Dim strSql As String

Dim da As New SqlDataAdapter()
Dim ds As New DataSet()

'##################begin:得到目录####################################
sql = "select contentsid,name from contents where magazineID=8 order by contentsindex "
da = New SqlDataAdapter(sql, conn)

ds.Clear()
da.Fill(ds, "contents ")

sql = "select articleid, contentsid,name,ename,subhead,esubhead,au_search,istop from article order by ArticleIndex "
da = New SqlDataAdapter(sql, conn)


da.Fill(ds, "article ")

'创建 Authors 表和 Titles 表之间的关系.
ds.Relations.Add( "myrelation ", ds.Tables( "contents ").Columns( "contentsid "), ds.Tables( "article ").Columns( "contentsid "))

rpContents.DataSource = ds.Tables( "contents ")
rpContents.DataBind()

'##################E N D:得到目录####################################

conn.Dispose()
End Sub
End Class
'################ End: repeater.aspx.vb ##########################


'################## Begin: repeater.aspx ##########################
<%@ Page Language= "VB " AutoEventWireup= "false " CodeFile= "repeater.aspx.vb " Inherits= "repeater " %>


<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
</head>
<body>
<form id= "form1 " runat= "server ">


<TABLE WIDTH= "764 " BORDER= "0 " CELLSPACING= "0 " CELLPADDING= "0 " ALIGN= "CENTER ">
<TR>
<TD WIDTH= "30 " BGCOLOR= "#FAFCFF " ROWSPAN= "4 " VALIGN= "TOP ">   </TD>
<TD WIDTH= "150 " BGCOLOR= "A2DABE " ROWSPAN= "4 " VALIGN= "TOP ">
<BR> <P>    <IMG SRC= "images/ad8.jpg "> </P> </TD>
<TD BGCOLOR= "#FFFFFF " VALIGN= "TOP " HEIGHT= "5 "> </TD>
<TD BGCOLOR= "#FFFFFF " VALIGN= "TOP " WIDTH= "20 "> </TD>
</TR>
<TR>
<TD BGCOLOR= "#FFFFFF " HEIGHT= "10 " ALIGN= "LEFT " CLASS= "songtida ">       <BR> </TD>
<TD BGCOLOR= "#FFFFFF ">   </TD>
</TR>
<TR>
<TD BGCOLOR= "#FFFFFF " COLSPAN= "2 ">
<TABLE WIDTH= "90% " BORDER= "0 " CELLSPACING= "0 " CELLPADDING= "0 " height=1 ALIGN= "CENTER ">
<TR> <TD BGCOLOR= "#000000 "> </TD> </TR>
</TABLE>
</TD>
</TR>

<TR>
<TD BGCOLOR= "#FFFFFF " COLSPAN= "2 " HEIGHT= "350 " VALIGN= "TOP ">


<asp:Repeater ID= "rpContents " runat= "Server ">
<ItemTemplate>
<b> <%#DataBinder.Eval(Container.DataItem, "name ")%> </b> <br>

'#######################此行报错 #############################
<asp:Repeater ID= "rptArticle " DataSource= " <%# Container.DataItem( "myrelation ") %> " runat= "server ">
'#######################报错 #############################


<ItemTemplate>
<%#Eval( "a_no ")%>
</ItemTemplate>
</asp:Repeater>
</TD>
</tr>
</ItemTemplate>
</asp:Repeater>

</td>
</tr>


</TABLE>
</form>
</body>
</html>
'##################### End: repeater.aspx #########################



[解决办法]
<%# ((System.Data.DataRowView)Container.DataItem).Row.GetChildRows( "myrelation ") %>
[解决办法]
如果你想这样写,建议你的子Repeater的DataSource用一个方法得到

DataSource= ' <%# GetMyRelation(DataBinder.Eval(Container.DataItem, "name ").ToString()) %> '

然后在你的后置代码中根据这个name再得到其myrelation
[解决办法]
up
net_lover(【孟子E章】)
[解决办法]

<asp:Repeater ID= "rptArticle " DataSource= " <%# Container.DataItem( "myrelation ") %> " runat= "server ">
改成
<asp:Repeater ID= "rptArticle " DataSource= " <%# Container.DataItem( "myrelation ") %> " runat= "server "/>
试试

读书人网 >asp.net

热点推荐