【发布时间】:2009-01-22 18:33:51
【问题描述】:
我有一个 ListView,它绑定到 LinqDataSource 并显示选定的位置。插入项包含一个下拉列表,该下拉列表从另一个 LinqDataSource 中提取以提供所有未选择的位置。
问题是我在加载页面时收到以下错误:
Eval()、XPath() 和 Bind() 等数据绑定方法只能在数据绑定控件的上下文中使用。
我在网站的另一个页面中进行了非常相似的设置,但它没有给我们这个错误,所以我很困惑。我知道我可以通过不绑定、手动查找控件并获取值来解决此问题,但这应该可以工作,但我不明白为什么不能。
有什么想法吗?
源代码更好的部分如下。
<asp:LinqDataSource ID="ldsLocations" runat="server"
ContextTypeName="ClearviewInterface.ESLinqDataContext" EnableDelete="true" EnableInsert="true"
OnInserting="ldsLocations_Inserting" OnDeleting="ldsLocations_Deleting"
TableName="crmLocations" OrderBy="addr1" OnSelecting="ldsLocations_Selecting" />
<asp:LinqDataSource ID="ldsFreeLocations" runat="server"
ContextTypeName="ClearviewInterface.ESLinqDataContext" OrderBy="addr1"
TableName="v_CVLocations" OnSelecting="ldsFreeLocations_Selecting" />
<asp:ListView ID="lvLocations" DataSourceID="ldsLocations" DataKeyNames="ID" InsertItemPosition="LastItem" runat="server" >
<InsertItemTemplate>
<tr>
<td colspan="6"><hr /></td>
</tr>
<tr>
<td colspan="2">
<asp:DropDownList ID="ddlFreeLocations" DataSourceID="ldsFreeLocations" DataTextField="addr1"
DataValueField="record" MarkFirstMatch="true" SelectedValue='<%# Bind("record") %>'
runat="server" />
</td>
<td><asp:ImageButton ID="btnAdd" CommandName="Insert" SkinID="Insert" runat="server" /></td>
</tr>
</InsertItemTemplate>
【问题讨论】:
-
当Dropdownlist在Listview中时,绑定在Dropdown的SelectedValue中不起作用...正如您所说的那样,您在另一个正在运行的网站中具有相同的设置...您是否仅在Listview中或在formview或gridview中放置了下拉列表???我也搜索了很多博客,因为我遇到了同样的问题。但我发现只有一个解决方案。 tht 使用 Eval 显示值并在 ItemInserting 和 itemUpdating 中“插入”或“更新”代码
-
如果您找到任何解决方案。在列表视图中的下拉列表中进行绑定...请也提供给我...
标签: asp.net linq-to-sql data-binding