是否可以在设计时将gridview与多个表数据绑定?
本文关键字:数据绑定 gridview 是否 | 更新日期: 2023-09-27 17:53:22
如何在设计模式下将多个表数据绑定到网格视图。
这是我的设计
<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;
在您的存储过程中,您编写了以下代码
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>