0

我有一个连接两个表的 LINQ 表达式。我想将“列表”绑定到 Gridview。代码在 Gridview 模板中出现此错误: DataBinding:“SearchResult”不包含名为“codereq”的属性。

IQueryable<SearchResult> myList = from t in TBL_Apartment
    join k in TBL_Owner on t.Code equals k.Code
    where k.CodeReq == t.CodeReq

        select new SearchResult
        {
           codereq= t.CodeReq,
           name = t.Name
        }

public class SearchResult
{
    public string codereq;
    public string name;
}

绑定 Gridview 代码:

    GridSearch.DataSource = myList.ToList();
    GridSearch.DataBind();

因为我的网格视图的 aspx 页面如下:

<telerik:RadGrid ID="GridSearch" runat="server" Skin="Office2007" AutoGenerateColumns="False"
        dir="rtl" Width="750px" GridLines="None" >

<MasterTableView>
<Columns>

<telerik:GridTemplateColumn HeaderText="Request Code" FilterControlWidth="100px">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("codereq")==""?"0":Eval("codereq") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>

<telerik:GridTemplateColumn HeaderText="Owner Name" FilterControlWidth="100px">
<ItemTemplate>
<asp:Label ID="Lbl_Mahale" runat="server" Text='<%# Eval("name")==""?"":Eval("name") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>

</Columns>
</MasterTableView>

<PagerStyle AlwaysVisible="True" />
<ClientSettings><Selecting AllowRowSelect="True" /></ClientSettings>

</telerik:RadGrid>
4

1 回答 1

0

这应该有帮助

var myCodeReq = 1; (or some other type of variable)

    List<SearchResult> myList = (from t in TBL_Apartment join k in TBL_Owner on t.Code equals k.Code where k.CodeReq == myCodeReq select new SearchResult { codereq = t.CodeReq, name = t.Name }).ToList();

    GridSearch.DataSource = myList;
    GridSearch.DataBind();
于 2012-07-10T05:57:48.657 回答