如何将网格视图列分成不同的行
本文关键字:网格 视图 | 更新日期: 2023-09-27 17:56:29
我有一个最多绑定 36 列的网格视图。当然,这看起来很糟糕。
我尝试将所有列设置为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 |VR12VR13 |VR14 |VR15 |VR16 |VR17 |VR18 |VR19 |VR20 |VR21 |VR22 |VR23 |VR24...
有什么建议吗?
问题相关(业务逻辑有点不清楚),最简单的方法是将两个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 链接: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeatdirection(v=vs.110).aspx