2013-01-14 60 views
1

我有以下的sql查詢,我想要在gridview中顯示,基本上是爲了加入字段。在網格視圖的綁定字段中顯示多個數據字段

我該怎麼做?

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在一個領域

<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> 
+0

檢查答案....將爲你工作.. –

回答

4

你想要什麼上面is to use an<asp:templatefield>代替<asp:boundfield>

步驟2中的鏈接顯示了使用模板列的一種方式。這裏是另一個:

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

我加入了<div>,表明您可以使用基本的文本和HTML在<ItemTemplate>

相關問題