大家好!我用的是 entity,页面控件是一个Telerik的Grid 自动生成增、删、改。编辑页面有一个下拉列表,当点击编辑的时候把数据自动带过来的。DicTypeID是外键,怎么直接绑定外键的列。当我点击添加或编辑提示我找不到该列。不知道怎么解决!!!大家帮看看!!!谢谢!!!!郁闷好几天了。
代码如下:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
AllowAutomaticUpdates="True" DataSourceID="EntityDataSource1" GridLines="None"
OnItemUpdated="RadGrid1_ItemUpdated" OnInsertCommand="RadGrid1_InsertCommand"
OnItemCommand="RadGrid1_ItemCommand">
<MasterTableView AutoGenerateColumns="False" HorizontalAlign="NotSet" CommandItemDisplay="TopAndBottom"
DataKeyNames="DicID" DataSourceID="EntityDataSource1">
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
</telerik:GridEditCommandColumn>
<telerik:GridBoundColumn DataField="DicID" HeaderText="DicID" SortExpression="DicName"
UniqueName="DicID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DicDode" HeaderText="DicDode" SortExpression="DicDode"
UniqueName="DicDode">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DicName" HeaderText="DicName" SortExpression="DicName"
UniqueName="DicName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DicRe" HeaderText="DicRe" SortExpression="DicRe"
UniqueName="DicRe">
</telerik:GridBoundColumn>
<telerik:GridDropDownColumn DataType="System.Guid" DataField="d_DicType.DicTypeID" DataSourceID="EntityDataSource2"
ListTextField="TypeName" ListValueField="DicTypeID" HeaderText="d_DicType.DicTypeID"
SortExpression="d_DicType.DicTypeID" UniqueName="d_DicType.DicTypeID">
</telerik:GridDropDownColumn>
<telerik:GridButtonColumn HeaderText="Delete" ConfirmText="Delete this product?"
ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton"
CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
<ItemStyle HorizontalAlign="Center" />
</telerik:GridButtonColumn>
</Columns>
<EditFormSettings EditFormType="Template" ColumnNumber="2" CaptionDataField="RoleName">
<EditColumn ButtonType="ImageButton" InsertText="Insert Order" UpdateText="Update record"
UniqueName="EditCommandColumn1" CancelText="Cancel edit">
</EditColumn>
<FormTableStyle CellSpacing="0" CellPadding="2" Height="110px" BackColor="White" />
<FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" BackColor="White"
Width="100%" />
<FormTableItemStyle Wrap="False"></FormTableItemStyle>
<FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
<FormTableButtonRowStyle HorizontalAlign="Right"></FormTableButtonRowStyle>
<FormTemplate>
<table align="center" border="2" cellpadding="2" cellspacing="1" style="width: 100%;
border-collapse: collapse;">
<tr>
<td style="width: 100px; height: 40px">
<telerik:RadTextBox ID="DicID" runat="server" Text='<%# Bind("DicID") %>' Width="150px"
Visible="false">
</telerik:RadTextBox>
DicDode:
</td>
<td style="height: 30px">
<telerik:RadTextBox ID="RadTextBox_UserName" runat="server" Text='<%# Bind("DicDode") %>'
Width="150px">
</telerik:RadTextBox>
</td>
<td style="width: 120px; height: 30px">
DicName:
</td>
<td style="height: 30px">
<telerik:RadTextBox ID="RadTextBox_LoginName" runat="server" Text='<%# Bind("DicName") %>'
Width="150px">
</telerik:RadTextBox>
</td>
</tr>
<tr>
<td style="width: 100px; height: 40px">
DicRe:
</td>
<td style="height: 30px">
<telerik:RadTextBox ID="RadTextBox3" runat="server" Text='<%# Bind("DicRe") %>' Width="150px">
</telerik:RadTextBox>
</td>
<td style="width: 120px; height: 30px">
DicTypeID:
</td>
<td style="height: 30px">
<telerik:RadComboBox ID="ComboBox1" runat="server" DataSourceID="EntityDataSource2"
DataTextField="TypeName" DataValueField="DicTypeID" AppendDataBoundItems="true"
SelectedValue='<%# Bind("DicTypeID") %>' >
</telerik:RadComboBox>
</td>
</tr>
<tr>
<td colspan="4" align="center">
<asp:Button ID="btnUpdate" runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' />
<asp:Button ID="btnCancel" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel" />
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=UnicornDBEntities"
DefaultContainerName="UnicornDBEntities" EnableDelete="True" EnableInsert="True"
EnableUpdate="True" EntitySetName="d_DicInfo" EntityTypeFilter="d_DicInfo">
</asp:EntityDataSource>
</div>
<asp:EntityDataSource ID="EntityDataSource2" runat="server" ConnectionString="name=UnicornDBEntities"
DefaultContainerName="UnicornDBEntities" EntitySetName="d_DicType"
EntityTypeFilter="d_DicType">
</asp:EntityDataSource>
假如a实体中有个外键 关联B实体中的字段 可以在建entity时在A用b实体存储
像
protected B B1;
public B b1
{
get { B1; }
set { OnPropertyChanged("B1", b1, value); B1= b1; };
}
绑定的时候用B1点出来就行了
添加reference的entitykey