我需要在页脚模板中将总数放在彼此下方。在第 5 列之前,包含数据的行之后不应有网格线,然后在总列之后再次出现网格线。
这是 ASPX 代码:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" SelectedRowStyle-BackColor="AliceBlue"
ShowFooter="True" EnableModelValidation="True"
onrowdatabound="LineItemGrid_RowDataBound" onrowcommand="GridView1_RowCommand" CellSpacing="0"
style="border-width:2px;border-style:Solid;font-weight:bold;width:1050px;">
<Columns>
<asp:TemplateField HeaderText="xxx">
<ItemTemplate>
<asp:Label ID="lbl1" runat="server" Text='Label' ></asp:Label>
</ItemTemplate>
<asp:TemplateField HeaderText="yyyy">
<ItemTemplate>
<asp:Label ID="lbl2" runat="server" Text='Label' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
///....Two other template fields here....
</asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lbltotal" runat="server" Text='' ></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox runat="server" ID="txttotalprice" ReadOnly="true" Width="100px" BorderStyle="None" ></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
请帮助我如何在页脚模板中应用下面要求的格式....
最佳答案
订阅 GridView_RowDataBound 事件
然后你可以这样做:
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for(int i = 0; i < e.Row.Cells.Count; i++)
{
if(i > 5)
{
e.Row.Cells[i].CssClass = "CellBorder";
}
}
}
}
您需要使用索引和条件(以及 CSS!)
关于asp.net - GridView 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8358482/