2011-02-04 83 views
0
<asp:GridView ID="GridView2" runat="server" AllowPaging="True" AutoGenerateColumns="False" 
           DataSourceID="opendiarysource" Font-Size="Small" style="font-size: 8pt; border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid; color: black;" AllowSorting="True" > 
           <Columns> 
            <asp:TemplateField HeaderText="Date Added" SortExpression="added7"> 
             <EditItemTemplate> 
              <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("added7") %>'></asp:TextBox> 
             </EditItemTemplate> 
             <ItemTemplate> 
              <br /> 
              <asp:Label ID="Label1" runat="server" Text='<%# Bind("added7") %>'></asp:Label><br /> 
              &nbsp; 
             </ItemTemplate> 
            </asp:TemplateField> 
            <asp:BoundField DataField="ByWhom" HeaderText="Added By" SortExpression="ByWhom" /> 
            <asp:BoundField DataField="BOOKNO" HeaderText="Book #" SortExpression="BOOKNO" /> 
            <asp:BoundField DataField="ClearedBy" HeaderText="Cleared By" SortExpression="ClearedBy" Visible="False" /> 
            <asp:BoundField DataField="Done7" HeaderText="Date Done" SortExpression="Done7" Visible="False" /> 
            <asp:BoundField DataField="ForWhom" HeaderText="For Whom" SortExpression="ForWhom" /> 

我希望這最後一個字段顯示爲下方的行而不是列。顯示gridview列作爲行

        <asp:TemplateField HeaderText="Note" SortExpression="Text"> 
             <EditItemTemplate> 
              <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Text") %>'></asp:TextBox> 
             </EditItemTemplate 

             <ItemTemplate> 
              <asp:Label ID="Label3" runat="server" Text='<%# Bind("Text") %>'></asp:Label> 
             </ItemTemplate> 
            </asp:TemplateField> 
           </Columns> 
          </asp:GridView> 

回答

1

嘗試使用ListView而不是GridView,如果這將是一個選項。這有很多模板功能。 的模板想:

<HeaderTemplate> 
      <table> 
     </HeaderTemplate> 
     <ItemTemplate> 

       <tr> 
        <td> 
         <asp:Label ID="Label1" runat="server" Text='<%# Eval("col1") %>' ></asp:Label> 
        </td> 
        <td> 
         <asp:Label ID="Label2" runat="server" Text='<%# Eval("col2") %>' ></asp:Label> 
        </td> 
       </tr> 
       <tr> 
        <td colspan="10"> 
         <asp:Label ID="Label3" runat="server" Text='<%# Eval("Text") %>' ></asp:Label> 
        </td> 
       </tr> 

     </ItemTemplate> 
     <EditItemTemplate> 

       <tr> 
        <td> 
         <asp:Label ID="Label1" runat="server" Text='<%# Eval("col1") %>' ></asp:Label> 
        </td> 
        <td> 
         <asp:Label ID="Label2" runat="server" Text='<%# Eval("col2") %>' ></asp:Label> 
        </td> 
       </tr> 
       <tr> 
        <td colspan="10"> 
         <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Text") %>' ></asp:TextBox> 
        </td> 
       </tr> 
     </EditItemTemplate> 
     <FooterTemplate> 
      </table> 
     </FooterTemplate> 
+0

我如何使用列表視圖,我使用VB 2005年,但沒有控制。因爲它在我的asp.net – MyHeadHurts 2011-02-04 17:07:53

1

通過這種方式轉換的所有行的列....

public DataTable ConvertColumnsAsRows(DataTable dt) 
{ 
    DataTable dtnew = new DataTable(); 

    for (int i = 0; i <= dt.Rows.Count; i++) 
    { 
     dtnew.Columns.Add(Convert.ToString(i)); 
    } 
    DataRow dr; 

    for (int j = 0; j < dt.Columns.Count; j++) 
    { 
     dr = dtnew.NewRow(); 
     dr[0] = dt.Columns[j].ToString(); 
     for (int k = 1; k <= dt.Rows.Count; k++) 
      dr[k] = dt.Rows[k - 1][j]; 
     dtnew.Rows.Add(dr); 
    } 
    return dtnew; 
} 

此功能用於列轉換爲行