1

基本的に結合されたフィールドに対して、グリッドビューに表示したい次のSQLクエリがあります。

これどうやってするの?

SELECT 
--RTRIM(C.CustomerFirstName) + ' ' + LTRIM(C.CustomerLastName) as CustomerFullName,
C.CustomerCompany,
C.CustomerPosition, 
C.CustomerCountry, 
C.CustomerProvince, 
C.CustomerContact,
CP.ActionDate, 
CP.ProductCode,
CP.CustomerEmail
     FROM tblCustomers C
    INNER JOIN 
    tblCustomerProducts CP ON 
C.CustomerEmail = CP.CustomerEmail
     ORDER BY ActionDate DESC

これはグリッド ビューの html です。基本的に、CustomerFirstName と CustomerLastName を 1 つのフィールドに入れたい

<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" 
        GridLines="None" Width="231px" AutoGenerateColumns="False">
        <RowStyle BackColor="#EFF3FB" />
        <Columns>
            **<asp:BoundField DataField="CustomerFirstName" HeaderText="Name" />
            <asp:BoundField DataField="CustomerLastName" HeaderText="Last Name" />**
            <asp:BoundField DataField="CustomerCompany" HeaderText="Company/Organisation" />
            <asp:BoundField DataField="CustomerPosition" HeaderText="Position" />
            <asp:BoundField DataField="CustomerCountry" HeaderText="Country" />
            <asp:BoundField DataField="CustomerProvince" HeaderText="Province" />
            <asp:BoundField DataField="CustomerContact" HeaderText="Contact" />
            <asp:BoundField DataField="CustomerEmail" HeaderText="Email Address" />
            <asp:BoundField DataField="ActionDate" HeaderText="Action Date" />
            <asp:BoundField DataField="ProductCode" HeaderText="Product code" />
        </Columns>
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <AlternatingRowStyle BackColor="White" />
    </asp:GridView>
4

1 に答える 1

4

あなたが望む のは、の代わりにを使用することです <asp:templatefield><asp:boundfield>

上記のリンクのステップ 2 は、テンプレート フィールドを使用する 1 つの方法を示しています。ここに別のものがあります:

<columns>
    <asp:TemplateField  HeaderText="Name">
    <ItemTemplate>
        <div><%#Eval("CustomerFirstName")%>, <%#Eval("CustomerLastName")%></div>
    </ItemTemplate>
<asp:BoundField>
....
</columns>

と を追加して、<div>,基本的なテキストと html を使用できることを示しました<ItemTemplate>

于 2013-01-14T14:02:47.793 に答える