我的RadGrid有问题...你能告诉我我的aspx文件怎么能用导航属性字段设置网格的列值?
我正在使用Entity,并且我将一个表SapDocuments与字段Process的外键处理到另一个表“Staging”,
此时我的网格的值为null ...
<MasterTableView GridLines="None" Width="100%" ViewStateMode="Disabled" CommandItemSettings-ShowExportToCsvButton="True"
CommandItemSettings-ShowAddNewRecordButton="false" CommandItemDisplay="Top">
<Columns>
<telerik:GridBoundColumn DataField="SequencialNumber" HeaderText="SequencialNumber"
UniqueName="SequencialNumber" SortExpression="SequencialNumber">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Priority" HeaderText="Priority" UniqueName="Priority"
FilterControlAltText="Filter Priority column" SortExpression="Priority" DataType="System.Int32">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Process" HeaderText="Staging" UniqueName="Process"
SortExpression="Process" FilterControlAltText="Filter Process column">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="SupplierCode" HeaderText="SupplierCode" UniqueName="SupplierCode"
SortExpression="SupplierCode" FilterControlAltText="Filter SupplierCode column">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="MessageStatus" HeaderText="MessageStatus" UniqueName="MessageStatus"
SortExpression="MessageStatus" FilterControlAltText="Filter MessageStatus column">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DocumentType" HeaderText="DocumentType" UniqueName="DocumentType"
FilterControlAltText="Filter DocumentType column" SortExpression="DocumentType">
</telerik:GridBoundColumn>
<telerik:GridDateTimeColumn UniqueName="InvoiceCreationDate" DataField="InvoiceCreationDate"
HeaderText="InvoiceCreationDate" FilterControlAltText="Filter InvoiceCreationDate column"
SortExpression="InvoiceCreationDate">
<FilterTemplate>
<telerik:RadDatePicker ID="RadDatePicker1" runat="server">
</telerik:RadDatePicker>
</FilterTemplate>
</telerik:GridDateTimeColumn>
<telerik:GridBoundColumn DataField="SupplierVatNumber" FilterControlAltText="Filter SupplierVatNumber column"
HeaderText="SupplierVatNumber" SortExpression="SupplierVatNumber" UniqueName="SupplierVatNumber">
</telerik:GridBoundColumn>
</Columns>
<ExpandCollapseColumn Visible="False">
<HeaderStyle Width="19px"></HeaderStyle>
</ExpandCollapseColumn>
<RowIndicatorColumn Visible="False">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
</MasterTableView>
<FilterMenu EnableImageSprites="False">
</FilterMenu>
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
</HeaderContextMenu>
</telerik:RadGrid
&GT;
我需要使用导航属性的值设置这两个列值....我可以像这样访问它:
SapDocuments.Priorities.Priority;
public List<SapDocuments> GetSapDocumentsByUser(string userName)
{
using (EscalonamentoFacturasEntities spDocs = new EscalonamentoFacturasEntities())
{
//Não é permitido projecções select new...
var documentsQuery = from sd in spDocs.SapDocuments
join ua in spDocs.UsersAssign
on new { sd.Staging.Process, sd.Priorities.Priority }
equals
new { ua.Process, ua.Priority }
where ua.UserName == userName
//ALterar User
select sd;
return documentsQuery.ToList();
我的代码背后是:
private void LoadData()
{
//Popular dados na Radlist
SapDocumentsBO sapDocs = new SapDocumentsBO();
this.SapDocuments = sapDocs.GetSapDocumentsByUser(Page.User.Identity.Name.Substring(Page.User.Identity.Name.IndexOf("\\")+1));
RadGrid1.DataSource = this.SapDocuments;
}
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
LoadData();
}
答案 0 :(得分:0)
您是否在对象上下文中启用了延迟加载?如果不是,关系将始终为null,您必须使用关联引用上的Load()方法手动实例化它们。更多相关内容:http://msdn.microsoft.com/en-us/library/dd456846.aspx
编辑:另外,你可以考虑
var documentsQuery = from sd in spDocs.SapDocuments
join ua in spDocs.UsersAssign
on new { sd.Staging.Process, sd.Priorities.Priority }
equals
new { ua.Process, ua.Priority }
where ua.UserName == userName
select new
{
spDocs.SequentialNumber,
Process = (spDocs.Staging != null) ? spDocs.Staging.Process : "",
Priority = (spDocs.Priorities != null) ? spDocs.Priorites.Priority : ""
};
并将结果返回为IQueryable或IList。这将使绑定变得非常容易。
此外,RadGrid确实支持点符号,我相信如下:
<telerik:GridBoundColumn DataField="Priorities.Priority" HeaderText="Priority" ...