GridViewCommandEventArgs 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
RowCommand 이벤트에 대한 데이터를 제공합니다.
public ref class GridViewCommandEventArgs : System::Web::UI::WebControls::CommandEventArgs
public class GridViewCommandEventArgs : System.Web.UI.WebControls.CommandEventArgs
type GridViewCommandEventArgs = class
inherit CommandEventArgs
Public Class GridViewCommandEventArgs
Inherits CommandEventArgs
- 상속
예제
다음 예제에서는 이벤트 처리 메서드에 전달 된 개체를 사용 하 여 GridViewCommandEventArgs 이벤트를 발생 시킨 단추의 명령 이름을 확인 하는 방법을 보여 줍니다.
<%@ 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 ContactsGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
// If multiple buttons are used in a GridView control, use the
// CommandName property to determine which button was clicked.
if(e.CommandName=="Add")
{
// Convert the row index stored in the CommandArgument
// property to an Integer.
int index = Convert.ToInt32(e.CommandArgument);
// Retrieve the row that contains the button clicked
// by the user from the Rows collection.
GridViewRow row = ContactsGridView.Rows[index];
// Create a new ListItem object for the contact in the row.
ListItem item = new ListItem();
item.Text = Server.HtmlDecode(row.Cells[2].Text) + " " +
Server.HtmlDecode(row.Cells[3].Text);
// If the contact is not already in the ListBox, add the ListItem
// object to the Items collection of the ListBox control.
if (!ContactsListBox.Items.Contains(item))
{
ContactsListBox.Items.Add(item);
}
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridView RowCommand Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridView RowCommand Example</h3>
<table width="100%">
<tr>
<td style="width:50%">
<asp:gridview id="ContactsGridView"
datasourceid="ContactsSource"
allowpaging="true"
autogeneratecolumns="false"
onrowcommand="ContactsGridView_RowCommand"
runat="server">
<columns>
<asp:buttonfield buttontype="Link"
commandname="Add"
text="Add"/>
<asp:boundfield datafield="ContactID"
headertext="Contact ID"/>
<asp:boundfield datafield="FirstName"
headertext="First Name"/>
<asp:boundfield datafield="LastName"
headertext="Last Name"/>
</columns>
</asp:gridview>
</td>
<td style="vertical-align:top; width:50%">
Contacts: <br/>
<asp:listbox id="ContactsListBox"
runat="server" Height="200px" Width="200px"/>
</td>
</tr>
</table>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the AdventureWorks sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:sqldatasource id="ContactsSource"
selectcommand="Select [ContactID], [FirstName], [LastName] From Person.Contact"
connectionstring="<%$ ConnectionStrings:AdventureWorks_DataConnectionString%>"
runat="server"/>
</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 ContactsGridView_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
' If multiple buttons are used in a GridView control, use the
' CommandName property to determine which button was clicked.
If e.CommandName = "Add" Then
' Convert the row index stored in the CommandArgument
' property to an Integer.
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
' Retrieve the row that contains the button clicked
' by the user from the Rows collection.
Dim row As GridViewRow = ContactsGridView.Rows(index)
' Create a new ListItem object for the contact in the row.
Dim item As New ListItem()
item.Text = Server.HtmlDecode(row.Cells(2).Text) & " " & _
Server.HtmlDecode(row.Cells(3).Text)
' If the contact is not already in the ListBox, add the ListItem
' object to the Items collection of the ListBox control.
If Not ContactsListBox.Items.Contains(item) Then
ContactsListBox.Items.Add(item)
End If
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>GridView RowCommand Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridView RowCommand Example</h3>
<table width="100%">
<tr>
<td style="width:50%">
<asp:gridview id="ContactsGridView"
datasourceid="ContactsSource"
allowpaging="true"
autogeneratecolumns="false"
onrowcommand="ContactsGridView_RowCommand"
runat="server">
<columns>
<asp:buttonfield buttontype="Link"
commandname="Add"
text="Add"/>
<asp:boundfield datafield="ContactID"
headertext="Contact ID"/>
<asp:boundfield datafield="FirstName"
headertext="First Name"/>
<asp:boundfield datafield="LastName"
headertext="Last Name"/>
</columns>
</asp:gridview>
</td>
<td style="vertical-align:top; width:50%">
Contacts: <br/>
<asp:listbox id="ContactsListBox"
runat="server" Height="200px" Width="200px"/>
</td>
</tr>
</table>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the AdventureWorks sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:sqldatasource id="ContactsSource"
selectcommand="Select [ContactID], [FirstName], [LastName] From Person.Contact"
connectionstring="<%$ ConnectionStrings:AdventureWorks_DataConnectionString%>"
runat="server"/>
</form>
</body>
</html>
설명
컨트롤 RowCommand 내 GridView 의 단추를 클릭할 때 이벤트가 발생합니다. 이렇게 하면 이 이벤트가 발생할 때마다 사용자 지정 루틴을 수행하는 이벤트 처리 메서드를 제공할 수 있습니다.
메모
컨트롤은 GridView 특정 단추를 클릭할 때 다른 특수한 이벤트도 발생합니다(예를 들어 속성이 "삭제", "업데이트" 및 "페이지"로 설정된 단추 CommandName ). 이러한 단추 중 하나를 사용하는 경우 컨트롤에서 제공하는 특수 이벤트(예: RowDeleted 또는 RowDeleting)를 처리하는 것이 좋습니다.
GridViewCommandEventArgs 개체가 이벤트 처리 메서드에 전달되므로 클릭한 단추의 명령 이름과 명령 인수를 확인할 수 있습니다. 명령 이름 및 명령 인수를 확인하려면 각각 및 CommandArgument 속성을 사용합니다CommandName. 속성을 사용하여 이벤트를 발생시킨 단추 컨트롤에 액세스할 수도 있습니다 CommandSource .
이벤트를 처리하는 방법에 대한 자세한 내용은 이벤트 처리 및 발생을 참조하세요.
인스턴스 GridViewCommandEventArgs의 초기 속성 값 목록은 생성자를 참조 GridViewCommandEventArgs 하세요.
생성자
| Name | Description |
|---|---|
| GridViewCommandEventArgs(GridViewRow, Object, CommandEventArgs) |
지정된 행, 명령 원본 GridViewCommandEventArgs 및 이벤트 인수를 사용하여 클래스의 새 인스턴스를 초기화합니다. |
| GridViewCommandEventArgs(Object, CommandEventArgs) |
명령 및 이벤트 인수의 GridViewCommandEventArgs 지정된 소스를 사용하여 클래스의 새 인스턴스를 초기화합니다. |
속성
| Name | Description |
|---|---|
| CommandArgument |
명령에 대한 인수를 가져옵니다. (다음에서 상속됨 CommandEventArgs) |
| CommandName |
명령의 이름을 가져옵니다. (다음에서 상속됨 CommandEventArgs) |
| CommandSource |
명령의 원본을 가져옵니다. |
| Handled |
컨트롤이 이벤트를 처리했는지 여부를 나타내는 값을 가져오거나 설정합니다. |
메서드
| Name | Description |
|---|---|
| Equals(Object) |
지정된 개체가 현재 개체와 같은지 여부를 확인합니다. (다음에서 상속됨 Object) |
| GetHashCode() |
기본 해시 함수로 사용됩니다. (다음에서 상속됨 Object) |
| GetType() |
현재 인스턴스의 Type 가져옵니다. (다음에서 상속됨 Object) |
| MemberwiseClone() |
현재 Object단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
| ToString() |
현재 개체를 나타내는 문자열을 반환합니다. (다음에서 상속됨 Object) |