0

在我的 SQL Server Express 中,我有Recipients,MailingListsRecipientMailingList( Recipient's ID 和MailingList's ID) 表。每个收件人都被分配到几个邮件列表。我想在GridView. 我想通过将表从服务器资源管理器拖放到.aspx源代码来实现这一点。但是,我得到的是一个GridView没有任何信息的信息,MailingLists就像其他表格中的信息一样。

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="RecipientID" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display.">
        <Columns>
            <asp:BoundField DataField="RecipientID" HeaderText="Recipient ID" ReadOnly="True" SortExpression="RecipientID" />
            <asp:BoundField DataField="FirstName" HeaderText="First Name" SortExpression="FirstName" />
            <asp:BoundField DataField="LastName" HeaderText="Last Name" SortExpression="LastName" />
            <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
            <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
            <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
            <asp:BoundField DataField="MailingLists" HeaderText="Mailing Lists" SortExpression="MailingLists" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NewsletterConnectionString1 %>" DeleteCommand="DELETE FROM [Recipients] WHERE [RecipientID] = @RecipientID" InsertCommand="INSERT INTO [Recipients] ([FirstName], [LastName], [City], [Email], [Phone]) VALUES (@FirstName, @LastName, @City, @Email, @Phone)" ProviderName="<%$ ConnectionStrings:NewsletterConnectionString1.ProviderName %>" SelectCommand="SELECT [RecipientID], [FirstName], [LastName], [City], [Email], [Phone] FROM [Recipients]" UpdateCommand="UPDATE [Recipients] SET [FirstName] = @FirstName, [LastName] = @LastName, [City] = @City, [Email] = @Email, [Phone] = @Phone WHERE [RecipientID] = @RecipientID">
        <DeleteParameters>
            <asp:Parameter Name="RecipientID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="FirstName" Type="String" />
            <asp:Parameter Name="LastName" Type="String" />
            <asp:Parameter Name="City" Type="String" />
            <asp:Parameter Name="Email" Type="String" />
            <asp:Parameter Name="Phone" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="FirstName" Type="String" />
            <asp:Parameter Name="LastName" Type="String" />
            <asp:Parameter Name="City" Type="String" />
            <asp:Parameter Name="Email" Type="String" />
            <asp:Parameter Name="Phone" Type="String" />
            <asp:Parameter Name="RecipientID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>

如何创建一个GridView(或可能的 ListView),其中包含这三个表中的所有信息(收件人的详细信息和邮件列表的名称)?

更新:我有这样一个查询用作数据源:

SELECT Recipients.RecipientID, Recipients.FirstName, Recipients.LastName, 
Recipients.City, Recipients.Email, Recipients.Phone, MailingLists.Name
FROM Recipients
INNER JOIN RecipientMailingList
ON Recipients.RecipientID = RecipientMailingList.Recipient_RecipientID
INNER JOIN MailingLists ON RecipientMailingList.MailingList_MailingListID = MailingLists.MailingListID

但是,我得到的是具有多个邮件列表的同一用户的不同行。我期望的结果是每个用户都有一行,一列是逗号分隔的MailingLists

4

1 回答 1

0

您可以使用模板字段并调用您的函数。

                <ItemTemplate>
             <%#GetName(Convert.ToInt32(Eval("RecipientsID"))) %>
         </ItemTemplate>
         </asp:TemplateField>

现在您必须在您的 cs 文件中编写一个函数来获取 int 值并返回字符串。

于 2013-01-14T17:01:59.923 回答