DataSource和DataSourceID都在'Repeater1'上定义

时间:2013-07-04 17:50:12

标签: c# sql dataset repeater

我有一个标准的Repeater,我想要做的就是添加分页,我不断收到标题中列出的错误。这是我的错误指向

 private void ItemsGet()
    {
        // Read sample item info from XML document into a DataSet
        DataSet Items = new DataSet();
        Items.ReadXml(MapPath("Items.xml"));

        // Populate the repeater control with the Items DataSet
        PagedDataSource objPds = new PagedDataSource();
        objPds.DataSource = Items.Tables[0].DefaultView;
        objPds.AllowPaging = true;
        objPds.PageSize = 3;

        objPds.CurrentPageIndex = CurrentPage;

        lblCurrentPage.Text = "Page: " + (CurrentPage + 1).ToString() + " of "
           + objPds.PageCount.ToString();

        // Disable Prev or Next buttons if necessary
        cmdPrev.Enabled = !objPds.IsFirstPage;
        cmdNext.Enabled = !objPds.IsLastPage;

        Repeater1.DataSource = objPds;
        Repeater1.DataBind();
    }

对于那些会问我会发布我的转发器的人

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="myFunction">
        <HeaderTemplate>
        </HeaderTemplate>
        <AlternatingItemTemplate>
        </AlternatingItemTemplate>             
        <ItemTemplate>
        </ItemTemplate>
        <FooterTemplate>
        </FooterTemplate>        
    </asp:Repeater>
    <tr>
        <td><asp:label id="lblCurrentPage" runat="server"></asp:label></td>
    </tr>

1 个答案:

答案 0 :(得分:2)

我相信您设置DataSourceID="SqlDataSource1"并设置Repeater1.DataSource = objPds;。设置一个或另一个。 在您的情况下,您可能想要删除DataSourceID="SqlDataSource1"