以下内容来自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>