如何更改Repeater DataSourceID?

时间:2013-04-24 01:01:25

标签: c# asp.net

我有一个转发器,而且我设置了DataSourceID

<asp:Repeater ID="rpProducts" runat="server" DataSourceID="ItemDataSource" >
    <HeaderTemplate>....</HeaderTemplate>
    <ItemTemplate>
       ....
    </ItemTemplate>
    <FooterTemplate>
    </FooterTemplate>
</asp:Repeater>

但有一段时间我想更改DataSourceID并加载数据并再次设置ItemDataSource

这是我更改rpProducts DataSourceID的代码。

rpProducts.DataSourceID = null;
rpProducts.DataSource = goods;
rpProducts.DataBind();

然后,我想再次将DataSourceID设置为ItemDataSource

我该怎么做?

我试试这样。但是没有工作

    rpProducts.DataSourceID = null;
    rpProducts.DataSourceID = ItemDataSource.ToString();

1 个答案:

答案 0 :(得分:1)

您可以尝试使用:ItemDataSource.ID
此外,无法同时设置datasource和datasourceid,因此您必须将数据源设置为null。

rpProducts.DataSource = null;
rpProducts.DataSourceID = ItemDataSource.ID;
rpProducts.DataBind();