在gridview中水平重复数据

时间:2014-01-08 13:29:10

标签: c# asp.net

我当前的GridView_RowDataBound显示的数据如下:

A B C D E

我想将其显示为:

A
B
C
D
E

有一个简单的方法吗?

我不确定Gridview是否可以这样做,我在GridView_RowDataBound的.cs端没有任何代码。

目前在excel导出上垂直重复数据,我希望它是水平的

日Thnx

<asp:Panel ID="Panel11" runat="server">
                        <span style="background-color: #">
                        <asp:GridView ID="GridView4" runat="server" AutoGenerateColumns="false" EnableModelValidation="True" 
                            onrowdatabound="GridView4_RowDataBound" ShowHeader="False" Visible="false"  
                            Width="700px">
                            <Columns>


                                 <asp:TemplateField HeaderText="Test">
                                    <EditItemTemplate>
                                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Test") %>'></asp:TextBox>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                    <asp:Label ID="Label1" runat="server" BackColor="Fuchsia" 
                                            Text='<%# Bind("Test") %>'></asp:Label>

                                    </ItemTemplate>
                                </asp:TemplateField>





                                 <asp:TemplateField HeaderText="Test2">
                                    <EditItemTemplate>
                                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Test2") %>'></asp:TextBox>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                   <asp:Label ID="Label2" runat="server" BackColor="Fuchsia" 
                                            Text='<%# Bind("Test2") %>'></asp:Label>

                                    </ItemTemplate>
                                </asp:TemplateField>

                            </Columns>

                            <EmptyDataRowStyle Height="6px" />
                            <FooterStyle Height="4px" />
                            <HeaderStyle Font-Size="X-Small" Height="10px" />
                            <RowStyle Font-Size="X-Small" Height="6px" HorizontalAlign="Left" 
                                VerticalAlign="Top" />
                        </asp:GridView>

                    </asp:Panel>

1 个答案:

答案 0 :(得分:1)

使用GridView你不能这样做..看看下面的细节。你想要的是GridView不支持的FlowLayout。

enter image description here

如果您更关注excel中的导出。我建议使用OpenOfficeXML将数据从DataTables导出到xls,如下文所述:

http://openxmldeveloper.org/discussions/development_tools/f/35/t/6033.aspx

Export DataTable to Excel with Open Xml SDK in c#