from:
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewrow.aspx

Visual Basic (Declaration)
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class GridViewRow _
Inherits TableRow _
Implements IDataItemContainer, INamingContainer
Visual Basic (Usage)
As GridViewRow
C#
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class GridViewRow : TableRow, IDataItemContainer,
INamingContainer
Visual C++
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class GridViewRow : public TableRow,
IDataItemContainer, INamingContainer
J#
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
public class GridViewRow extends TableRow implements IDataItemContainer,
INamingContainer
JScript
extends TableRow implements IDataItemContainer, INamingContainer
ASP.NET
/>

The GridViewRow class is used represent an individual row in a GridView control has a designated row type. The following table lists the different row types.

Row type

Description

DataGridRowType.DataRow

A data row in the GridView control.

DataGridRowType.Footer

The footer row in the GridView control.

DataGridRowType.Header

The header row in the GridView control.

DataGridRowType.NullRow

The null row in the GridView control when there are no records to display.

DataGridRowType.Pager

A pager row in the GridView control.

DataGridRowType.Separator

A separator row in the GridView control.

To determine the row type of a GridViewRow object, use the GridViewRow object also has a state associated with it. The state can be a bitwise combination of the values in the following table.

State value

Description

DataControlRowState.Alternate

The GridViewRow object is an alternate row in the GridView control.

DataControlRowState.Edit

The GridViewRow object is in edit mode.

DataControlRowState.Normal

The GridViewRow object is in its normal (default) state.

DataControlRowState.Selected

The GridViewRow object is selected.

To determine the state of a GridViewRow object, use the RowState property.

The RowIndex property.

You can access the properties of the underlying data object that is bound to the GridViewRow object by using the DataItem property.

[refference] gridviewclassNote:

The GridView control.

To determine the index of the data object in the underlying data source, use the DataItemIndex property.

You can access the individual cells of the GridViewRow object by using the ID specified.

To retrieve a field value from a Text property of the cell. To retrieve a field value from other field column types where the field value is bound to a control, first retrieve the control from the appropriate cell and then access the appropriate property of the control.

[refference] gridviewclassNote:

It is possible to use a data-binding expression directly in a Text property.

For a list of initial property values for an instance of GridViewRow, see the GridViewRow constructor.

The following example demonstrates how to use a GridViewRow object to retrieve a field value from a cell in the GridView control and then display the value on the page.

Visual Basic
 %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub AuthorsGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
' Get the selected row from the GridView control.
Dim selectRow As GridViewRow = AuthorsGridView.SelectedRow
' Get the author's first and last name from the appropriate
' cells in the selected row. For BoundField field columns
' and automatically generated field columns, the Text property
' of a cell is used to access a field value.
Dim lastName As String = selectRow.Cells(1).Text
' In a TemplateField column where a data-binding expression
' is used directly in the ItemTemplate, the field value
' is automatically placed in DataBoundLiteral control.
' Retrieve the DataBoundLiteral control from the cell. The
' DataBoundLiteral control is the first control in the 
' Controls collection.
Dim firstNameLiteral As DataBoundLiteralControl = CType(selectRow.Cells(2).Controls(0), DataBoundLiteralControl)
Dim firstName As String = firstNameLiteral.Text
' Display the name of the selected author.
Message.Text = "You selected " & firstName & " " & lastName & "."
End Sub
</script>
<html  >
<head runat="server">
<title>GridViewRow Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridViewRow Example</h3>
<asp:label id="Message"
forecolor="Red"
runat="server"/>
<br/>
<asp:gridview id="AuthorsGridView"
datasourceid="AuthorsSqlDataSource"
autogeneratecolumns="false"
autogenerateselectbutton="true"
onselectedindexchanged="AuthorsGridView_SelectedIndexChanged"
runat="server">
<columns>
<asp:boundfield datafield="au_lname"
headertext="Last Name"/>
<asp:templatefield headertext="FirstName">
<itemtemplate>
<%#Eval("au_fname")%>
</itemtemplate>
</asp:templatefield>
</columns>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Pubs sample database.                        -->
<asp:sqldatasource id="AuthorsSqlDataSource"
selectcommand="SELECT [au_lname], [au_fname], [address], [city], [state], [zip], [contract] FROM [authors]"
connectionstring="server=localhost;database=pubs;integrated security=SSPI"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
 %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void AuthorsGridView_SelectedIndexChanged(Object sender, EventArgs e)
{
// Get the selected row from the GridView control.
GridViewRow selectRow = AuthorsGridView.SelectedRow;
// Get the author's first and last name from the appropriate
// cells in the selected row. For BoundField field columns
// and automatically generated field columns, the Text property
// of a cell is used to access a field value.
String lastName = selectRow.Cells[1].Text;
// In a TemplateField column where a data-binding expression
// is used directly in the ItemTemplate, the field value
// is automatically placed in DataBoundLiteral control.
// Retrieve the DataBoundLiteral control from the cell. The
// DataBoundLiteral control is the first control in the 
// Controls collection.
DataBoundLiteralControl firstNameLiteral = (DataBoundLiteralControl)selectRow.Cells[2].Controls[0];
String firstName = firstNameLiteral.Text;
// Display the name of the selected author.
Message.Text = "You selected " + firstName + " " + lastName + ".";
}
</script>
<html  >
<head runat="server">
<title>GridViewRow Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridViewRow Example</h3>
<asp:label id="Message"
forecolor="Red"
runat="server"/>
<br/>
<asp:gridview id="AuthorsGridView"
datasourceid="AuthorsSqlDataSource"
autogeneratecolumns="false"
autogenerateselectbutton="true"
onselectedindexchanged="AuthorsGridView_SelectedIndexChanged"
runat="server">
<columns>
<asp:boundfield datafield="au_lname"
headertext="Last Name"/>
<asp:templatefield headertext="FirstName">
<itemtemplate>
<%#Eval("au_fname")%>
</itemtemplate>
</asp:templatefield>
</columns>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Pubs sample database.                        -->
<asp:sqldatasource id="AuthorsSqlDataSource"
selectcommand="SELECT [au_lname], [au_fname], [address], [city], [state], [zip], [contract] FROM [authors]"
connectionstring="server=localhost;database=pubs;integrated security=SSPI"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>

The following example demonstrates how to use a GridViewRow object to retrieve a SqlDataSource control for updating in the data source.

[refference] gridviewclassSecurity Note:

This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

Visual Basic
 %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub AuthorsGridView_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
' In this example, the GridView control will not automatically extract 
' updated values from TemplateField column fields because they are not
' using a two-way binding expression. So, the updated
' values must be added manually to the NewValues dictionary.
' Get the GridViewRow object that represents the row being edited
' from the Rows collection of the GridView control.
Dim index As Integer = AuthorsGridView.EditIndex
Dim row As GridViewRow = AuthorsGridView.Rows(index)
' Get the controls that contain the updated values. In this
' example, the updated values are contained in the TextBox 
' controls declared in the EditItemTemplates of the TemplateField 
' column fields in the GridView control.
Dim lastName As TextBox = CType(row.FindControl("LastNameTextBox"), TextBox)
Dim firstName As TextBox = CType(row.FindControl("FirstNameTextBox"), TextBox)
' Add the updated values to the NewValues dictionary. Use the
' parameter names declared in the parameterized update query 
' string for the key names.
e.NewValues("au_lname") = lastName.Text
e.NewValues("au_fname") = firstName.Text
End Sub
</script>
<html  >
<head runat="server">
<title>GridViewRow Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridViewRow Example</h3>
<!-- The GridView control automatically sets the columns     -->
<!-- specified in the datakeynames attribute as read-only    -->
<!-- No input controls are rendered for these columns in     -->
<!-- edit mode.                                              -->
<asp:gridview id="AuthorsGridView"
datasourceid="AuthorsSqlDataSource"
autogeneratecolumns="false"
autogenerateeditbutton="true"
datakeynames="au_id"
cellpadding="10"
onrowupdating="AuthorsGridView_RowUpdating"
runat="server">
<columns>
<asp:boundfield datafield="au_id"
headertext="Author ID"
readonly="true"/>
<asp:templatefield headertext="Last Name"
itemstyle-verticalalign="Top">
<itemtemplate>
<%#Eval("au_lname")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="LastNameTextBox"
text='<%#Eval("au_lname")%>'
width="90"
runat="server"/>
<br/>
<asp:requiredfieldvalidator id="LastNameRequiredValidator"
controltovalidate="LastNameTextBox"
display="Dynamic"
text="Please enter a last name."
runat="server" />
</edititemtemplate>
</asp:templatefield>
<asp:templatefield headertext="First Name"
itemstyle-verticalalign="Top">
<itemtemplate>
<%#Eval("au_fname")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="FirstNameTextBox"
text='<%#Eval("au_fname")%>'
width="90"
runat="server"/>
<br/>
<asp:requiredfieldvalidator id="FirstNameRequiredValidator"
controltovalidate="FirstNameTextBox"
display="Dynamic"
text="Please enter a first name."
runat="server" />
</edititemtemplate>
</asp:templatefield>
<asp:checkboxfield datafield="contract"
headertext="Contract"
readonly="true"/>
</columns>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Pubs sample database.                         -->
<asp:sqldatasource id="AuthorsSqlDataSource"
selectcommand="SELECT [au_id], [au_lname], [au_fname], [contract] FROM [authors]"
updatecommand="UPDATE authors SET au_lname=@au_lname, au_fname=@au_fname WHERE (authors.au_id = @au_id)"
connectionstring="server=localhost;database=pubs;integrated security=SSPI"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
 %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void AuthorsGridView_RowUpdating (Object sender, GridViewUpdateEventArgs e)
{
// In this example, the GridView control will not automatically extract 
// updated values from TemplateField column fields because they are not
// using a two-way binding expression. So, the updated
// values must be added manually to the NewValues dictionary.
// Get the GridViewRow object that represents the row being edited
// from the Rows collection of the GridView control.
int index = AuthorsGridView.EditIndex;
GridViewRow row = AuthorsGridView.Rows[index];
// Get the controls that contain the updated values. In this
// example, the updated values are contained in the TextBox 
// controls declared in the EditItemTemplates of the TemplateField 
// column fields in the GridView control.
TextBox lastName = (TextBox)row.FindControl("LastNameTextBox");
TextBox firstName = (TextBox)row.FindControl("FirstNameTextBox");
// Add the updated values to the NewValues dictionary. Use the
// parameter names declared in the parameterized update query 
// string for the key names.
e.NewValues["au_lname"] = lastName.Text;
e.NewValues["au_fname"] = firstName.Text;
}
</script>
<html  >
<head runat="server">
<title>GridViewRow Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridViewRow Example</h3>
<!-- The GridView control automatically sets the columns     -->
<!-- specified in the datakeynames attribute as read-only    -->
<!-- No input controls are rendered for these columns in     -->
<!-- edit mode.                                              -->
<asp:gridview id="AuthorsGridView"
datasourceid="AuthorsSqlDataSource"
autogeneratecolumns="false"
autogenerateeditbutton="true"
datakeynames="au_id"
cellpadding="10"
onrowupdating="AuthorsGridView_RowUpdating"
runat="server">
<columns>
<asp:boundfield datafield="au_id"
headertext="Author ID"
readonly="true"/>
<asp:templatefield headertext="Last Name"
itemstyle-verticalalign="Top">
<itemtemplate>
<%#Eval("au_lname")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="LastNameTextBox"
text='<%#Eval("au_lname")%>'
width="90"
runat="server"/>
<br/>
<asp:requiredfieldvalidator id="LastNameRequiredValidator"
controltovalidate="LastNameTextBox"
display="Dynamic"
text="Please enter a last name."
runat="server" />
</edititemtemplate>
</asp:templatefield>
<asp:templatefield headertext="First Name"
itemstyle-verticalalign="Top">
<itemtemplate>
<%#Eval("au_fname")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="FirstNameTextBox"
text='<%#Eval("au_fname")%>'
width="90"
runat="server"/>
<br/>
<asp:requiredfieldvalidator id="FirstNameRequiredValidator"
controltovalidate="FirstNameTextBox"
display="Dynamic"
text="Please enter a first name."
runat="server" />
</edititemtemplate>
</asp:templatefield>
<asp:checkboxfield datafield="contract"
headertext="Contract"
readonly="true"/>
</columns>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Pubs sample database.                        -->
<asp:sqldatasource id="AuthorsSqlDataSource"
selectcommand="SELECT [au_id], [au_lname], [au_fname], [contract] FROM [authors]"
updatecommand="UPDATE authors SET au_lname=@au_lname, au_fname=@au_fname WHERE (authors.au_id = @au_id)"
connectionstring="server=localhost;database=pubs;integrated security=SSPI"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
.Object
  .Control
    .WebControl
      .TableRow
        System.Web.UI.WebControls..::.GridViewRow
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

 

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0 SP1, 3.0, 2.0 SP1, 2.0

相关文章:

猜你喜欢
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案