中继器绑定了两个表



我正在asp.net中进行一个项目。我使用了两个嵌套中继器来显示状态和对该状态的评论。嵌套中继器绑定到具有两个表的数据源。现在,当我#Eval第二个表的列的值时,它显示了一个不包含属性名称错误。

  <ItemTemplate>
        <div  style="height:285px;">
        <img src='ProfilePic/<%#Eval("ProfilePic")%>' width="100" height="100" alt="" />
        <asp:LinkButton ID="lnkfrndname" OnClick="lnkfrndname_Click" CommandName="frndname" CommandArgument='<%#Eval("UserName") %>' runat="server"> <u><%#Eval("Firstname")%> <%#Eval("LastName")%></u></asp:LinkButton>
        <br />
        <%#Eval("StatusText")%>
        <br />
        <asp:HiddenField ID="hfstatusid" Value='<%# Eval("StatusId") %>' runat="<asp:Repeater ID="replike" runat="server">
            < <asp:Literal ID="ltlstatuscomm" Text='<%#Eval("CommentText") %>' runat="server"></asp:Literal>
        </ItemTemplate>
        </ </ItemTemplate>
</asp:Repeater>

.cs

protected void rephomecontent_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
        {
            HiddenField hf = e.Item.FindControl("hfstatusid") as HiddenField;
        if (hf != null)
        {
            Repeater rep = e.Item.FindControl("replike") as Repeater;
            if (rep != null)
            {

                int statusid = int.Parse(hf.Value.ToString());
                DataSet ds = new StatusLikeInfoAction().ViewStatusLike(statusid);
                rep.DataSource = ds;
                rep.DataBind();
             }
          }
        }
       }

如果将转发器与Datatable绑定,而不是与包含多个表的DataSet绑定,那将是一件好事。

首先分析是否要绑定

ds.Tables[0]

ds.表[1]

然后按照以下绑定中继器

rep.DataSource = ds.Tables[0];

rep.DataSource = ds.Tables[1];

根据您的选择

最新更新