RadGrid 设置列导航属性
我的 RadGrid 遇到问题...您能告诉我如何在我的 aspx 文件上使用导航属性字段设置网格的列值吗?
我正在使用实体,并且我有一个表 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
>
我需要使用导航属性的值设置这两列值...我可以这样访问它:
- SapDocuments.Staging.Process;
SapDocuments.Priorities.Priority;
公共列表
GetSapDocumentsByUser(字符串用户名) { 使用 (EscalonamentoFacturasEntities spDocs = new EscalonamentoFacturasEntities()) { //不要允许项目选择新的... var DocumentsQuery = 来自 spDocs.SapDocuments 中的 sd 将 ua 加入 spDocs.UsersAssign 关于新的{sd.Staging.Process,sd.Priorities.Priority} 等于 新的 { ua.Process, ua.Priority } 其中 ua.UserName == 用户名 //ALterar用户 选择SD; 返回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();
}
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否在对象上下文上启用了延迟加载?如果不是,关系将始终为空,并且您必须使用关联引用上的 Load() 方法手动实例化它们。更多信息请参见:http://msdn.microsoft.com/en-us/ library/dd456846.aspx
编辑:另外,您可以考虑
并将结果返回为 IQueryable 或 IList。这将使绑定变得非常容易。
另外,RadGrid 确实支持点表示法,我相信如下所示:
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
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: