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

时间:2015-06-16 18:31:11

标签: c# asp.net gridview

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

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

我也尝试在我的边界上使用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>

以下是更改标题的代码

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

有任何建议吗?

2 个答案:

答案 0 :(得分:1)

与您的问题相关(业务逻辑有点不清楚),最简单的方法是将两个GridView对象绑定到同一个DataSource但具有不同的列,因此第一个{{ 1}}将:

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列。希望这可能是肝脏。

答案 1 :(得分:0)

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

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