.net GridViewRow.RowType 属性

本文介绍了.NET Framework 2.0中新添加的GridViewRowType属性,该属性用于确定GridViewRow对象所代表的行类型。文章通过示例展示了如何利用此属性来识别不同类型的行,并在创建或绑定数据时进行相应的操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以下内容来自MSDN

注意:此属性在 .NET Framework 2.0 版中是新增的。

获取 GridViewRow 对象的行类型。

命名空间:System.Web.UI.WebControls

属性值
DataControlRowType 值之一。

备注
使用 RowType 属性确定 GridViewRow 对象表示的行的类型。下表列出了不同的行类型值。



此属性通常用于在执行一个操作前确定行的类型。

示例
下面的示例演示如何使用 RowType 属性确定要创建的行是否为脚注行。如果该行是脚注行,列的总和值将更新到脚注行。

<%@ Page language="C#" %>

<script runat="server">
 
  // Create a variable to store the order total.
  private Decimal orderTotal = 0.0M;

  void OrderGridView_RowCreated(Object sender, GridViewRowEventArgs e)
  {
   
    // Retrieve the current row.
    GridViewRow row = e.Row;
   
    // Update the column total if the row being created is
    // a footer row.
    if (row.RowType == DataControlRowType.Footer)
    {
     
      // Get the OrderTotalTotal Label control in the footer row.
      Label total = (Label)e.Row.FindControl("OrderTotalLabel");
     
      // Display the grand total of the order formatted as currency.
      if (total != null)
      {
        total.Text = orderTotal.ToString("c");
      }
     
    }
   
  }
 
  void OrderGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
  {
  
    // Retrieve the current row.
    GridViewRow row = e.Row;
   
    // Add the field value to the column total if the row being created is
    // a data row.
    if (row.RowType == DataControlRowType.DataRow)
    {
     
      // Get the cell that contains the item total.
      TableCell cell = e.Row.Cells[2];
     
      // Get the DataBoundLiteralControl control that contains the
      // data bound value.
      DataBoundLiteralControl boundControl = (DataBoundLiteralControl)cell.Controls[0];
     
      // Remove the '$' character for the type converter to work properly.
      String itemTotal = boundControl.Text.Replace("$",  "");
     
      // Add the total for an item (row) to the order total.
      orderTotal += Convert.ToDecimal(itemTotal);
     
    }
   
  }
 
</script>

<html>
  <body>
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值