是否可以在设计时将gridview与多个表数据绑定

时间:2011-04-28 13:01:51

标签: c# asp.net gridview

如何在设计模式下将多个表数据绑定到网格视图。

这是我的设计

  <asp:GridView ID="grdACH" runat="server" AutoGenerateColumns="False" BackColor="White"
            BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black"
            GridLines="Vertical" Style="left: 121px; position: absolute; top: 133px">
            <Columns>
                <asp:TemplateField>
                    <HeaderTemplate>
                        <asp:CheckBox ID="CheckAll" runat="server" onclick="return check_uncheck (this );" />
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="ID" runat="server" Text='<%# DataBinder.Eval (Container.DataItem, "FedTaxID") %>'
                            Visible="false"></asp:Label>
                        <asp:CheckBox ID="checkRec" runat="server" onclick="return check_uncheck (this );" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="FedTaxID" SortExpression="FedTaxID">
                    <EditItemTemplate>
                        <asp:Label ID="lblFedTaxID" runat="server" Text='<%# Eval("FedTaxID") %>'></asp:Label>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblFedTaxID1" runat="server" Text='<%# Bind("FedTaxID") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="CompanyName" HeaderText="CompanyName"></asp:BoundField>
                <asp:BoundField DataField="EntryDescription" HeaderText="CompanyEntryDescription"></asp:BoundField>
                <asp:BoundField DataField="BankRoutingNumber" HeaderText="RoutingNumber"></asp:BoundField>
                <asp:BoundField DataField="Amount" HeaderText="Amount"></asp:BoundField>
  

这是另一张表

    <asp:TemplateField HeaderText="TaxAuthority" SortExpression="Taxing_Auth_Name">
                    <EditItemTemplate>
                        <asp:Label ID="lblTaxAuthority" runat="server" Text='<%# Eval("Taxing_Auth_Name") %>'></asp:Label>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblTaxAuthority" runat="server" Text='<%# Bind("Taxing_Auth_Name") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>


            </Columns>
            <RowStyle BackColor="#F7F7DE" />
            <FooterStyle BackColor="#CCCC99" />
            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
            <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>

但我收到的错误为DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Taxing_Auth_Name'.

任何人都可以告诉你做什么

我执行绑定的存储过程

  select c.fedtaxid,companyname,'comapany desc',c.entrydescription,
  c.BankRoutingNumber,
  g.Amount,g.TaxAuthority from tblcustomer c join (
  select swc.fedtaxid As FedTaxID,sum(amount)  Amount, taxing_auth_name TaxAuthority from tbl_employees_swc_grosswagedetails swc where wage_code='GRTT' and    taxing_auth_name='FED' and (empid,payperiodnumber,payyear)  in (select distinct  empid,PayPeriodID,payyear  from tblcpyresults cpyr where  cpyr.fedtaxid=swc.fedtaxid )   group by swc.fedtaxid) g on c.fedtaxid=g.fedtaxid;

1 个答案:

答案 0 :(得分:0)

在你的商店程序中你写了这个

 taxing_auth_name TaxAuthority 

因此,使用TaxAuthority定义您的标签,这将解决问题..

如下所示

    <asp:TemplateField HeaderText="TaxAuthority" SortExpression="TaxAuthority">
                <EditItemTemplate>
                    <asp:Label ID="lblTaxAuthority" runat="server" Text='<%# Eval("TaxAuthority") %>'></asp:Label>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblTaxAuthority" runat="server" Text='<%# Bind("TaxAuthority") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>