I'm having a problem with my RadGrid...Can you show me how can i on my aspx file set the column value of my grid with a navigation property field?
I'm using Entity, and I have the a table SapDocuments with a foreign Key of the field Process to another Table "Staging",
At this moment my grid comes with its value at 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
>
I need to set those two column values with the value of my navigation property....I can access to it like that:
- SapDocuments.Staging.Process;
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();
My code behind is this:
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();
}
Did you enable lazy loading on the object context? If not, relationships will always be null, and you would have to manually instantiate them using the Load() method on the associated reference. More on that here: http://msdn.microsoft.com/en-us/library/dd456846.aspx
EDIT: Also, you could consider
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 : ""
};
And return the result as IQueryable or IList. That would make it really easy to bind.
Also, the RadGrid does support dot notation i believe like the following:
<telerik:GridBoundColumn DataField="Priorities.Priority" HeaderText="Priority" ...
精彩评论