我有一个供应商投标的网格视图,其中包含供应商表和产品表的外键。
这是我的gridview 和我的数据源。
<table>
<asp:GridView ID="GridViewVendorBids" runat="server" AutoGenerateColumns="False"
DataSourceID="VendorBidsDS" DataKeyNames="autRecNum" ForeColor="#333333" CellPadding="4"
GridLines="None" AllowPaging="True" AllowSorting="True">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField ShowEditButton="true" />
<asp:BoundField DataField="dtmBidDate" HeaderText="Bid Date" SortExpression="dtmBidDate"
DataFormatString="{0:MM/dd/yyyy}" ApplyFormatInEditMode="true" />
<asp:TemplateField HeaderText="Vendor Name" SortExpression="it.tblVendors.strVendorName">
<ItemTemplate>
<asp:Label ID="lblVendorName" runat="server" Text='<%# Eval("tblVendors.strVendorName") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlVendorList" runat="server" DataTextField="strVendorName"
DataSource='<%# getVendorList() %>' DataValueField="strVendorCode" AutoPostBack="false"
SelectedValue='<%# Bind("strVendorCode") %>' DropDownStyle="DropDownList" AutoCompleteMode="SuggestAppend"
CssClass="comboBoxInsideModalPopup" Width="250px" MaxLength="0" Style="display: inline;
top: 0px; left: 0px;" ItemInsertLocation="Append" RenderMode="Inline" Height="16px" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Product Name" SortExpression="it.tblProducts.strProductName">
<ItemTemplate>
<asp:Label ID="lblProductName" runat="server" Text='<%# Eval("tblProducts.strProductName") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlProductList" runat="server" DataTextField="strProductName"
DataSource='<%# getProductList() %>' DataValueField="strProductCode" AutoPostBack="false"
SelectedValue='<%# Bind("strProductCode") %>' DropDownStyle="DropDownList" AutoCompleteMode="SuggestAppend"
CssClass="comboBoxInsideModalPopup" Width="300px" MaxLength="0" Style="display: inline;
top: 0px; left: 0px;" ItemInsertLocation="Append" RenderMode="Inline" Height="16px" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit" SortExpression="it.tblProducts.strUnitDesc">
<ItemTemplate>
<asp:Label ID="lblUnitDesc" runat="server" Text='<%# Eval("tblProducts.strUnitDesc") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="sngBid" HeaderText="Bid" SortExpression="sngBid" ItemStyle-HorizontalAlign="Right"
DataFormatString="{0:0.00}" />
<asp:BoundField DataField="strBidType" HeaderText="Bid Type" SortExpression="strBidType"
ReadOnly="true" />
<asp:CommandField ShowDeleteButton="true" />
</Columns>
</asp:GridView>
</table>
<asp:EntityDataSource ID="VendorBidsDS" runat="server" ConnectionString="name=IMSEntities"
DefaultContainerName="IMSEntities" EntitySetName="tblVendorBid" Include="tblVendors,tblProducts"
EnableFlattening="False" OrderBy="it.dtmBidDate DESC" EnableDelete="true" EnableUpdate="true">
</asp:EntityDataSource>
当我按下更新或删除键时,出现以下错误:
在更新或删除操作期间未找到关键属性值。检查以确保指定为绑定表达式的关键属性可用于数据源。
我发现这篇文章与我的问题非常相似,但是当我尝试答案时,我仍然得到同样的错误。
任何帮助表示赞赏。谢谢。