GridViewRowCollection.Item[Int32] 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 인덱스의 GridViewRow 개체를 가져옵니다.
public:
property System::Web::UI::WebControls::GridViewRow ^ default[int] { System::Web::UI::WebControls::GridViewRow ^ get(int index); };
public System.Web.UI.WebControls.GridViewRow this[int index] { get; }
member this.Item(int) : System.Web.UI.WebControls.GridViewRow
Default Public ReadOnly Property Item(index As Integer) As GridViewRow
매개 변수
- index
- Int32
컬렉션에서 검색할 GridViewRow 개체의 인덱스입니다.
속성 값
컬렉션의 지정된 인덱스에 있는 GridViewRow 개체입니다.
예제
다음 예제에서는 인덱서를 사용 하 여 검색 하는 방법에 설명 된 GridViewRow 컬렉션의 개체입니다. 셀의 값을 GridViewRow 개체는 페이지에 표시 됩니다.
<%@ Page language="C#" %>
<!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)
{
// The GridView control does not automatically extract updated values
// from TemplateField column fields. These 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 xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridViewRowCollection Indexer Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridViewRowCollection Indexer 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>
<%@ Page language="VB" %>
<!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)
' The GridView control does not automatically extract updated values
' from TemplateField column fields. These 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 xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridViewRowCollection Indexer Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridViewRowCollection Indexer 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>
설명
이 인덱서를 사용 하 여 검색을 GridViewRow 배열 표기법을 사용 하 여 지정 된 인덱스 컬렉션에서 개체입니다.