我是 ASP.NET 的新手。我有一个列出公司名称的基本工作网格视图(参见下面的代码)。我想做的是在每个公司下提供另一个联系人子列表,在“子列表”中缩进一点。
我想以某种方式遍历 Gridview 数据,然后运行联系人查询,将是“Select * from Import_Contact where Company = 'The Company from the GridView DataSource'”,然后显示每个公司下的联系人的子集。输出应如下所示:
1) Company A
1) Contact x
2) Contact y
1) Contact x
2) Company B
1) Contact h
2) Contact i
很快 ...
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
AllowPaging="False"
SelectedIndex="0"
DataSourceID="dsUploadList"
ShowHeaderWhenEmpty="True" EmptyDataText="No records Found"
EnableRowClick = "False" Width="100%" AllowSorting="True"
AutoGenerateEditButton="False"
>
<Columns>
<asp:BoundField ReadOnly="True" HeaderText="Row" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="5%"
InsertVisible="False" DataField="Row"
SortExpression="Row" />
<asp:BoundField ReadOnly="True" HeaderText="Company" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="30%"
InsertVisible="False" DataField="Company"
SortExpression="Company" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="dsUploadList" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnApps %>"
SelectCommand="SELECT DISTINCT(Company)
, ROW_NUMBER() OVER (ORDER By Company ASC) AS Row
FROM dbo.Import_CompanyContact icc WHERE RefNum = @RefNum "
>
<SelectParameters>
<asp:QueryStringParameter Name="RefNum" QueryStringField="RefNum" DefaultValue="0" Type="Int16" />
</SelectParameters>
关于如何做到这一点的任何建议?一个很棒的代码示例。谢谢。