【问题标题】:What causes 'Both DataSource and DataSourceID are defined on 'DataListCity'. Remove one definition' error?是什么原因导致“DataListCity”上定义了“DataSource 和 DataSourceID”。删除一个定义的错误?
【发布时间】:2015-04-02 03:21:30
【问题描述】:

我收到这个错误

“DataSource 和 DataSourceID 都在 'DataListCity' 上定义。删除一个定义。”

这是我的 Masterpage 中导致错误的代码

<asp:DataList ID="DataListCity" runat="server" Width="100%" 
    onitemcommand="DataListCity_ItemCommand" CellPadding="4" 
    ForeColor="#333333" DataSourceID="SqlDataSource1">

    <ItemTemplate>
        CityId:
        <asp:Label ID="CityIdLabel" runat="server" Text='<%# Eval("CityId") %/>
        <br />
        CityName:
        <asp:Label ID="CityNameLabel" runat="server" Text='<%# Eval("CityName")%>' />
        <br />
        <br />
    </ItemTemplate>
</asp:DataList>

<asp:SqlDataSource
    ConnectionString="<%$ ConnectionStrings:HotelConnString %>" 
    ID="SqlDataSource1" runat="server"   
    SelectCommand="SELECT [CityId], [CityName], [Description] FROM [Categories]">
</asp:SqlDataSource>

【问题讨论】:

  • 你是否也在后面的代码中添加了这个?

标签: c# asp.net .net


【解决方案1】:

如果您已经在代码后面编写了代码,请从 cs 中删除您的绑定代码,因为您只能通过代码后面或来自设计的代码进行绑定,而不能同时进行两者

从后面的代码中删除这些行

DataListCity.DataSource=somesource;
DataListCity.DataBind();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-29
    • 2011-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多