0

I have a repeater and and and I set its DataSourceID .

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

But I some time I want to change the DataSourceID and load data and again set the ItemDataSource.

This is my code for change the rpProducts DataSourceID .

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

So then again I want to set the DataSourceID to ItemDataSource.

How can I do it?

I try like this. but is not working

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

1 回答 1

2

你可以试试:ItemDataSource.ID
另外,datasource 和 datasourceid 不能同时设置,所以你必须将 datasource 设置为 null。

rpProducts.DataSource = null;
rpProducts.DataSourceID = ItemDataSource.ID;
rpProducts.DataBind();
于 2013-04-24T01:09:38.120 回答