【问题标题】:Repeater bound with two tables与两个表绑定的中继器
【发布时间】:2014-04-29 16:57:21
【问题描述】:

我正在 asp.net 中开发一个项目。我使用了两个嵌套中继器来显示状态和该状态的 cmets。嵌套转发器绑定到具有两个表的数据源。现在,当我 #Eval 第二个表的列的值时,它显示 not contains property name 错误。

  <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();
             }
          }
        }
       }

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    如果你用Datatable而不是包含多个表的DataSet来绑定repeater就好了。

    先分析是否要绑定

    ds.Tables[0]

    或者

    ds.Tables[1]

    然后按如下方式绑定转发器

    rep.DataSource = ds.Tables[0];
    

    或者

    rep.DataSource = ds.Tables[1];
    

    根据您的选择

    【讨论】:

    • 感谢它的工作,但只是为了好奇,如果我需要将转发器与两个表绑定怎么办
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-11
    • 2011-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-19
    • 2019-01-29
    相关资源
    最近更新 更多