【问题标题】:Both DataSource and DataSourceID are defined on 'CuisineList'. Remove one definitionDataSource 和 DataSourceID 都在“CuisineList”上定义。删除一个定义
【发布时间】:2012-08-28 00:21:49
【问题描述】:

我尝试了一些在 Google 和 Stack Overflow 上找到的建议,但它们都不起作用。

这是我的数据绑定到的下拉列表控件 - 请注意,它没有 DataSouce 或 DataSourceID 的值

<asp:DropDownList ID="CuisineList" runat="server" Width="100" 
     onselectedindexchanged="CuisineList_SelectedIndexChanged">
</asp:DropDownList>

下面是将数据绑定到下拉列表控件的代码:

BLgetMasterData obj = new BLgetMasterData();
var cusineList = obj.getCuisines();
CuisineList.DataSourceID = null; 
CuisineList.DataSource = cusineList;
CuisineList.DataBind();
CuisineList.Items.Insert(0, "Any");
CuisineList.SelectedValue = "Any";

【问题讨论】:

  • 不要认为这会导致您的问题,但为什么会有这条线? CuisineList.DataSourceID = null;
  • 这是我在堆栈溢出中找到的建议之一
  • 我建议你三遍检查没有其他代码设置DataSourceID,错误很清楚,不会出错
  • 我在我的项目中执行了“查找”,但没有引用 datasourceid

标签: c# asp.net linq-to-entities datasource


【解决方案1】:

CuisineList.DataBind(); 将使用数据源的数据填充您的列表。
就像您在列表中插入了额外的项目一样,您也可以删除它们。

CuisineList.Items.Remove("Item");
CuisineList.Items.RemoveAt(1);
CuisineList.Items.Remove(someOtherList.SelectedItem);

参考:dropdownlist items remove method

【讨论】:

  • 我不确定这与我提出的问题有何关系。
  • 您的问题表明“删除一个定义”。如果您不是在问如何从列表中删除项目,您在问什么?
  • 嗨......我不是想从集合中删除一个项目,我想将集合上的某个属性设置为空。我想我没有说清楚。
【解决方案2】:

即使我检查了没有使用 DataSourceID 的页面后面的属性和代码,我也面临同样的问题。由于数据库身份验证,我发现它给出错误。请检查您的数据库。

谢谢

【讨论】:

    【解决方案3】:

    这个错误是因为你给的两个数据源可能在不同的位置。 转到您的 aspx 设计文件并从 DropDownList 字段中删除 DataSourceId 属性。

    【讨论】:

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