2011-12-02 133 views
0

我需要在页脚模板中彼此之下的总数。应该有数据行,直到第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> 

Pleaes帮助我如何在页脚模板中应用以下要求的格式...

+1

似乎它并没有我,你是需要分页,排序或任何特定的Gridview功能。在这种情况下,为什么不建立自己的HTML表格并按照您的要求进行设计?只是一个想法。 –

+0

寻呼将包括在内 – Janet

+0

这并不是那么简单。你应该看的是GridView_RowDataBound事件。每次绑定一行时,都会触发此事件,并从传递的Row对象中访问单元。然后你可以遍历每个单元格并设置一个CSS样式。使用不同类型的控件可能会更容易,但是,正如您所说,您可能需要分页等 – dash

回答

0

订阅GridView_RowDataBound事件

然后,您可以这样做:(!和CSS)

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";  
     } 
    } 

    } 

} 

您需要使用索引和条件,发挥