asp.net - GridView 格式

标签 asp.net css

我需要在页脚模板中将总数放在彼此下方。在第 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/

相关文章:

css - 无法获取显示 :block element (instead a display:flex element) to contain it's child in IE11

asp.net - 如何找出哪个页面是默认页面?

子窗口中的 JavaScript 错误

asp.net - Web应用程序的NTier架构的替代方案

css - 如何隐藏/显示具有动态高度的 div 的内容?

javascript - 如何添加简单的图片上传功能?

html - 用于显示聊天文本消息的最佳 html 标签?

c# - 如何在 IIS 中正确发布和更新 ASP.NET 应用程序

C#:有什么工具可以自动从类生成接口(interface)?

javascript - IE7 是否错误地报告了 "position"的计算值?