将 gridview 列显示为行 [英] display gridview column as row

查看:29
本文介绍了将 gridview 列显示为行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <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" />

我希望最后一个字段显示为下面的一行而不是一列.

I want this last field to show up as a row underneath instead of a column.

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

推荐答案

尝试使用 ListView 而不是 GridView,如果这对您来说是一种选择.这有很多模板功能.模板希望:

Try to use ListView instead of GridView, if that would be an option for you. That has lot of templating features. The Templates would like:

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

这篇关于将 gridview 列显示为行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆