我有一个通过联合多个表构建的网格视图。每个表都有一个称为 Pkey 的主键。我的问题是gridview在显示数据时遇到相同的Pkey编号时出错。
Here is the query
SELECT Pkey, Status, EffectiveDate, 'Budget Element' as RequestType, DescribeRequest
FROM tblBudgetElement
union
SELECT Pkey, Status, EffectiveDate, 'Expense Element' as RequestType, DescribeRequest
FROM tblExpenseElement
union
SELECT Pkey, Status, EffectiveDate, 'Expense Hl' as RequestType, DescribeRequest
FROM tblExpenseHLevel
我尝试过使用简单的绑定字段。并尝试在后面的代码中创建一个超链接字段。
这是网格视图
<asp:BoundField DataField="Pkey" HeaderText="Pkey">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="RequestType" HeaderText="Request Type">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Status" HeaderText="Status">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="EffectiveDate" HeaderText="Effective Date" DataFormatString = "{0:d}" >
<HeaderStyle HorizontalAlign="center" />
<ItemStyle HorizontalAlign="center" />
</asp:BoundField>
<asp:BoundField DataField="DescribeRequest" HeaderText="Describe Request">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:TemplateField>
<HeaderStyle VerticalAlign="Top" BorderWidth="0"/>
<ItemStyle BorderWidth="0"/>
<ItemTemplate>
<asp:Image runat="server" BorderStyle="None" ID="Image1" ImageUrl="~/Images/MagnifyingClass.gif" />
<cc1:PopupControlExtender ID="PopupControlExtender1" runat="server"
PopupControlID="Panel1"
TargetControlID="Image1"
DynamicContextKey='<%# Eval("Pkey") %>'
DynamicControlID="Panel1"
DynamicServiceMethod="GetRequest" Position="right">
</cc1:PopupControlExtender>
<asp:Panel ID="Panel1" runat="server"></asp:Panel>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Silver" Font-Bold="True" ForeColor="Black" />
<AlternatingRowStyle BackColor="#CCCCCC" />
</asp:GridView>