如何将 gridview 列分成不同的行?

How to break gridview columns into different rows?

我有一个最多可绑定 36 列的 gridview。这当然看起来很糟糕。

我尝试将所有列设置为 itemTemplates,然后分成行。问题是我的 header 标题不固定。

我也试过在我的边界域上使用 CSS,但它确实不起作用。

这就是我所拥有的

<asp:GridView ID="Gv1" runat="server" AutoGenerateColumns="False" DataSourceID="dsGv1"  CssClass="table table-hover table-striped" GridLines="None" OnPreRender="Gv1_PreRender">
                    <Columns>
                        <asp:BoundField DataField="vr1" HeaderText="vr1" ReadOnly="True" SortExpression="vr1" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr2" HeaderText="vr2" ReadOnly="True" SortExpression="vr2" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr3" HeaderText="vr3" ReadOnly="True" SortExpression="vr3" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr4" HeaderText="vr4" ReadOnly="True" SortExpression="vr4" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr5" HeaderText="vr5" ReadOnly="True" SortExpression="vr5" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr6" HeaderText="vr6" ReadOnly="True" SortExpression="vr6" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr7" HeaderText="vr7" ReadOnly="True" SortExpression="vr7" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr8" HeaderText="vr8" ReadOnly="True" SortExpression="vr8" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr9" HeaderText="vr9" ReadOnly="True" SortExpression="vr9" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr10" HeaderText="vr10" ReadOnly="True" SortExpression="vr10" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr11" HeaderText="vr11" ReadOnly="True" SortExpression="vr11" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr12" HeaderText="vr12" ReadOnly="True" SortExpression="vr12" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr13" HeaderText="vr13" ReadOnly="True" SortExpression="vr13" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr14" HeaderText="vr14" ReadOnly="True" SortExpression="vr14" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr15" HeaderText="vr15" ReadOnly="True" SortExpression="vr15" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr16" HeaderText="vr16" ReadOnly="True" SortExpression="vr16" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr17" HeaderText="vr17" ReadOnly="True" SortExpression="vr17" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr18" HeaderText="vr18" ReadOnly="True" SortExpression="vr18" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr19" HeaderText="vr19" ReadOnly="True" SortExpression="vr19" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr20" HeaderText="vr20" ReadOnly="True" SortExpression="vr20" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr21" HeaderText="vr21" ReadOnly="True" SortExpression="vr21" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr22" HeaderText="vr22" ReadOnly="True" SortExpression="vr22" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr23" HeaderText="vr23" ReadOnly="True" SortExpression="vr23" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr24" HeaderText="vr24" ReadOnly="True" SortExpression="vr24" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr25" HeaderText="vr25" ReadOnly="True" SortExpression="vr25" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr26" HeaderText="vr26" ReadOnly="True" SortExpression="vr26" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr27" HeaderText="vr27" ReadOnly="True" SortExpression="vr27" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr28" HeaderText="vr28" ReadOnly="True" SortExpression="vr28" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr29" HeaderText="vr29" ReadOnly="True" SortExpression="vr29" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr30" HeaderText="vr30" ReadOnly="True" SortExpression="vr30" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr31" HeaderText="vr31" ReadOnly="True" SortExpression="vr31" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr32" HeaderText="vr32" ReadOnly="True" SortExpression="vr32" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr33" HeaderText="vr33" ReadOnly="True" SortExpression="vr33" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr34" HeaderText="vr34" ReadOnly="True" SortExpression="vr34" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr35" HeaderText="vr35" ReadOnly="True" SortExpression="vr35" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr36" HeaderText="vr36" ReadOnly="True" SortExpression="vr36" DataFormatString="{0:c}"/>
                        <asp:BoundField DataField="vr_total" HeaderText="Valor Total" ReadOnly="True" SortExpression="vr_total" DataFormatString="{0:c}"/>
                    </Columns>
                </asp:GridView>

这是更改我的 headers

的代码
for (int i = 0; i < gv.Columns.Count-1; i++)
            {
                gv.Columns[i].HeaderText = dt.AddMonths(-11+i).ToString("MM/yyyy"); 
            }

所以..我有这个
VR01 | VR02 | VR03 | VR04 | VR05 | VR06 | VR07 | VR08 | VR09 | VR10 | VR11 | VR12 | VR13 | VR14 | VR15 | VR16 | VR17 | VR18 | VR19 | VR20 | VR21 | VR22 | VR23 | vr24

我正在寻找这样的东西:
VR01 | VR02 | VR03 | VR04 | VR05 | VR06 | VR07 | VR08 | VR09 | VR10 | VR11 | VR12
VR13 | VR14 | VR15 | VR16 | VR17 | VR18 | VR19 | VR20 | VR21 | VR22 | VR23 | VR24 ...

有什么建议吗?

与您的问题相关(w/business 逻辑有点不清楚),最简单的方法是将两个 GridView 对象绑定到相同的 DataSource 但具有不同的列,所以第一个 GridView 将有:

vr01 | vr02 | vr03 | vr04 | vr05 | vr06 | vr07 | vr08 | vr09 | vr10 | vr11 | vr12

和第二个 GridView 放在下面将有其余的列:

vr13 | vr14 | vr15 | vr16 | vr17 | vr18 | vr19 | vr20 | vr21 | vr22 | vr23 | vr24 ... 

或者,您可能只有一个 GridView,然后创建一个 TemplateField,并根据您的任务安排列。希望这可能会有所帮助。

您也可以使用 asp:DataList 并设置 RepeatDirection="Horizontal"RepeatColumns="12"

MSDN Link:https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeatdirection(v=vs.110).aspx