Asp.net使用数据绑定表达式与int

时间:2016-01-08 16:58:10

标签: asp.net bind

我有一个名为Quotation的表,其中一列名为Gross_Total,类型为Int。当我使用Bind方法将它绑定到gridview colunm时,如下所示:

<asp:TemplateField HeaderText="Price">
    <ItemTemplate>
        <asp:Label ID="lblPrice" runat="server" Text='<%# Bind("Gross_Total") %>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>

我得到一个很长的运行时错误:

  

DataBinding:'&lt;&gt; f__AnonymousType015 [[System.Int32,mscorlib,   版本= 4.0.0.0,文化=中立,   PublicKeyToken = b77a5c561934e089],[System.String,mscorlib,   版本= 4.0.0.0,文化=中立,   PublicKeyToken = b77a5c561934e089],[System.String,mscorlib,   版本= 4.0.0.0,文化=中立,   PublicKeyToken = b77a5c561934e089],[System.String,mscorlib,   版本= 4.0.0.0,文化=中立,   PublicKeyToken = b77a5c561934e089],[System.Int32,mscorlib,   版本= 4.0.0.0,文化=中立,   PublicKeyToken = b77a5c561934e089],[System.String,mscorlib,   版本= 4.0.0.0,文化=中立,   PublicKeyToken = b77a5c561934e089],[System.String,mscorlib,   版本= 4.0.0.0,文化=中立,   公钥= b77a5c561934e089],[System.Nullable1 [[System.Int32,   mscorlib,版本= 4.0.0.0,文化=中性,   PublicKeyToken = b77a5c561934e089]],mscorlib,Version = 4.0.0.0,   文化=中性,   公钥= b77a5c561934e089],[System.Nullable`1 [[System.Int32,   mscorlib,版本= 4.0.0.0,文化=中性,   PublicKeyToken = b77a5c561934e089]],mscorlib,Version = 4.0.0.0,   Culture = neutral,Pu ...'不包含具有名称的属性   'Gross_Total'。

我的数据绑定方法:

 if (!IsPostBack)
    {
        MajesticEntities majesticentities = new MajesticEntities();
        var query = majesticentities.Quotations
                    .Select(quote => new
                    {
                        quote.Id,
                        quote.Bank,
                        quote.Customer.First_name,
                        quote.Customer.Surname,
                        quote.CPR,
                        quote.Car.Maker,
                        quote.Car.Type,
                        quote.Down_Payment,
                        quote.Gross_Total,
                        quote.Balance,
                        quote.Installments,
                        quote.Bank_Employee,
                        quote.Status_Bank,
                        quote.Notes_Bank,
                        quote.Status_Invoice,
                        quote.Notes_Invoice
                    });
        gridSample.DataSource = query.ToList();
        gridSample.DataBind();

        var query2 = from b in majesticentities.Banks
                     select b.Name;
        DropDownListBanks.DataSource = query2.ToList();
        DropDownListBanks.DataBind();
    }

更新

网格视图源代码

<asp:GridView ID="gridSample" runat="server" DataKeyNames="Id" ForeColor="#99ccff" >
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:TemplateField HeaderText="">
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkEdit" runat="server" Text="" CommandName="edit" CommandArgument=""> 
                             <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/document_edit.png" Height="50px" Width="50px"/> </asp:LinkButton>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:LinkButton ID="LinkInsert" runat="server" Text="" ValidationGroup="editGrp" CommandName="Update" CommandArgument="">
                            <asp:Image ID="Image2" runat="server" />     <asp:Image ID="Image3" runat="server" ImageUrl="~/Images/save.png"/> </asp:LinkButton>
                        <asp:LinkButton ID="LinkCancel" runat="server" Text="" CommandName="CancelNew" CommandArgument="">
                            <asp:Image ID="Image4" runat="server" ImageUrl="~/Images/back-2-1.png" />
                        </asp:LinkButton>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Ref">
                    <ItemTemplate> 
                        <asp:Label ID="lblQuotationId" runat="server" Text='<%# Bind("Id") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="First Name">
                    <ItemTemplate>
                        <asp:Label ID="lblFirstName" runat="server" Text='<%# Bind("First_name") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtFirstName" runat="server" Text='<%# Bind("First_name") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="valFirstName" runat="server" ControlToValidate="txtFirstName"
                                Display="Dynamic" ErrorMessage="First Name is required." ForeColor="Red" SetFocusOnError="True"
                               ValidationGroup="editGrp">*</asp:RequiredFieldValidator>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Surname">
                    <ItemTemplate>
                        <asp:Label ID="lblSurname" runat="server" Text='<%# Bind("Surname") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="CPR">
                    <ItemTemplate>
                        <asp:Label ID="lblSurname" runat="server" Text='<%# Bind("CPR") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Car">
                    <ItemTemplate>
                        <asp:Label ID="lblCarMaker" runat="server" Text='<%# Bind("Maker") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Model">
                    <ItemTemplate>
                        <asp:Label ID="lblCarType" runat="server" Text='<%# Bind("Type") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Price">
                    <ItemTemplate>
                        <asp:Label ID="lblPrice" runat="server" Text='<%# Bind("Gross_Total") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Down Payment">
                    <ItemTemplate>
                        <asp:Label ID="lblDownPayment" runat="server" Text='<%# Bind("Down_Payment") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Balance">
                    <ItemTemplate>
                        <asp:Label ID="lblBalance" runat="server" Text='<%# Bind("Balance") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Bank">
                    <ItemTemplate>
                        <asp:Label ID="lblBank" runat="server" Text='<%# Bind("Bank") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
    </asp:GridView>

0 个答案:

没有答案