BaseDataList.SelectedIndexChanged 이벤트
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
서버에 게시되는 중간에 데이터 목록 컨트롤에서 다른 항목이 선택될 때 발생합니다.
public:
event EventHandler ^ SelectedIndexChanged;
public event EventHandler SelectedIndexChanged;
member this.SelectedIndexChanged : EventHandler
Public Custom Event SelectedIndexChanged As EventHandler
이벤트 유형
예제
다음 코드 예제에서는 선언적으로 이벤트에 대 SelectedIndexChanged 한 이벤트 처리기를 제공 하는 방법을 보여 줍니다.
<%@ Page Language="C#" AutoEventWireup="True"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Declarative BaseDataList SelectedIndexChanged Example</title>
<script runat="server">
ICollection CreateDataSource()
{
// Create sample data for the DataGrid control.
DataTable dt = new DataTable();
DataRow dr;
// Define the columns of the table.
dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));
// Populate the table with sample values.
for (int i = 0; i < 9; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = "Item " + i.ToString();
dr[2] = 1.23 * (i + 1);
dt.Rows.Add(dr);
}
// Create a DataView from the DataTable.
DataView dv = new DataView(dt);
return dv;
}
void Page_Load(Object sender, EventArgs e)
{
// Load sample data only once, when the page is first loaded.
if (!IsPostBack)
{
ItemsGrid.DataSource = CreateDataSource();
ItemsGrid.DataBind();
}
}
void IndexChange_Command(Object sender, EventArgs e)
{
// Display the details of the selected item.
DetailsLabel.Text =
"Item Number: " + ItemsGrid.SelectedItem.Cells[1].Text + "<br />" +
"Description: " + ItemsGrid.SelectedItem.Cells[2].Text + "<br />" +
"Price: $" + ItemsGrid.SelectedItem.Cells[3].Text + "<br />";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>Declarative BaseDataList SelectedIndexChanged Example</h3>
Select an item:
<br /><br />
<asp:DataGrid id="ItemsGrid"
BorderColor="Black"
ShowFooter="False"
CellPadding="3"
CellSpacing="0"
HeaderStyle-BackColor="#aaaadd"
OnSelectedIndexChanged="IndexChange_Command"
runat="server">
<Columns>
<asp:ButtonColumn Text="Select"
CommandName="Select"/>
</Columns>
</asp:DataGrid>
<hr />
<table style="border-width:1; border-color:Black; margin:0">
<tr style="background-color:#aaaadd">
<td>
Details
</td>
</tr>
<tr>
<td>
<asp:Label id="DetailsLabel"
runat="server"
Text="No item selected."/>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Declarative BaseDataList SelectedIndexChanged Example</title>
<script runat="server">
Function CreateDataSource() As ICollection
' Create sample data for the DataGrid control.
Dim dt As DataTable = New DataTable()
Dim dr As DataRow
' Define the columns of the table.
dt.Columns.Add(New DataColumn("IntegerValue", GetType(Integer)))
dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))
' Populate the table with sample values.
Dim i As Integer
For i = 0 to 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " & i.ToString()
dr(2) = 1.23 * (i + 1)
dt.Rows.Add(dr)
Next i
' Create a DataView from the DataTable.
Dim dv As DataView = New DataView(dt)
Return dv
End Function
Sub Page_Load(sender As Object, e As EventArgs)
' Load sample data only once when the page is first loaded.
If Not IsPostBack Then
ItemsGrid.DataSource = CreateDataSource()
ItemsGrid.DataBind()
End If
End Sub
Sub IndexChange_Command(sender As Object, e As EventArgs)
' Display the details of the selected item.
DetailsLabel.Text = _
"Item Number: " & ItemsGrid.SelectedItem.Cells(1).Text & "<br />" & _
"Description: " & ItemsGrid.SelectedItem.Cells(2).Text & "<br />" & _
"Price: $" & ItemsGrid.SelectedItem.Cells(3).Text & "<br />"
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>Declarative BaseDataList SelectedIndexChanged Example</h3>
Select an item:
<br /><br />
<asp:DataGrid id="ItemsGrid"
BorderColor="Black"
ShowFooter="False"
CellPadding="3"
CellSpacing="0"
HeaderStyle-BackColor="#aaaadd"
OnSelectedIndexChanged="IndexChange_Command"
runat="server">
<Columns>
<asp:ButtonColumn Text="Select"
CommandName="Select"/>
</Columns>
</asp:DataGrid>
<hr />
<table border="1" style="border-color:Black; margin:0">
<tr style="background-color:#aaaadd">
<td>
Details
</td>
</tr>
<tr>
<td>
<asp:Label id="DetailsLabel"
runat="server"
Text="No item selected."/>
</td>
</tr>
</table>
</form>
</body>
</html>
다음 코드 예제에서는 이벤트에 대 SelectedIndexChanged 한 이벤트 처리기를 제공 하는 방법을 보여 줍니다는 프로그래밍 방식으로 이벤트입니다.
<%@ Page Language="C#" AutoEventWireup="True"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Programmatic BaseDataList SelectedIndexChanged Example</title>
<script runat="server">
ICollection CreateDataSource()
{
// Create sample data for the DataGrid control.
DataTable dt = new DataTable();
DataRow dr;
// Define the columns of the table.
dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));
// Populate the table with sample values.
for (int i = 0; i < 9; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = "Item " + i.ToString();
dr[2] = 1.23 * (i + 1);
dt.Rows.Add(dr);
}
// Create a DataView from the DataTable.
DataView dv = new DataView(dt);
return dv;
}
void IndexChange_Command(Object sender, EventArgs e)
{
// Display the details of the selected item.
DetailsLabel.Text = "Item Number: " + ItemsGrid.SelectedItem.Cells[1].Text + "<br />" +
"Description: " + ItemsGrid.SelectedItem.Cells[2].Text + "<br />" +
"Price: $" + ItemsGrid.SelectedItem.Cells[3].Text + "<br />";
}
void Page_Load(Object sender, EventArgs e)
{
// Load sample data only once, when the page is first loaded.
if (!IsPostBack)
{
// Load sample data.
ItemsGrid.DataSource = CreateDataSource();
ItemsGrid.DataBind();
}
// Register event-handling methods.
ItemsGrid.SelectedIndexChanged += new EventHandler(this.IndexChange_Command);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>Programmatic BaseDataList SelectedIndexChanged Example</h3>
Select an item:
<br /><br />
<asp:DataGrid id="ItemsGrid"
BorderColor="Black"
ShowFooter="False"
CellPadding="3"
CellSpacing="0"
HeaderStyle-BackColor="#aaaadd"
runat="server">
<Columns>
<asp:ButtonColumn Text="Select"
CommandName="Select"/>
</Columns>
</asp:DataGrid>
<hr />
<table border="1" style="border-color:Black; margin:0">
<tr style="background-color:#aaaadd">
<td>
Details
</td>
</tr>
<tr>
<td>
<asp:Label id="DetailsLabel"
runat="server"
Text="No item selected."/>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Programmatic BaseDataList SelectedIndexChanged Example</title>
<script runat="server">
Function CreateDataSource() As ICollection
' Create sample data for the DataGrid control.
Dim dt As DataTable = New DataTable()
Dim dr As DataRow
' Define the columns of the table.
dt.Columns.Add(New DataColumn("IntegerValue", GetType(Integer)))
dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))
' Populate the table with sample values.
Dim i As Integer
For i = 0 to 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " & i.ToString()
dr(2) = 1.23 * (i + 1)
dt.Rows.Add(dr)
Next i
' Create a DataView from the DataTable.
Dim dv As DataView = New DataView(dt)
Return dv
End Function
Sub Page_Load(sender As Object, e As EventArgs)
' Load sample data only once, when the page is first loaded.
If Not IsPostBack Then
ItemsGrid.DataSource = CreateDataSource()
ItemsGrid.DataBind()
End If
' Register event-handling methods.
AddHandler ItemsGrid.SelectedIndexChanged, AddressOf IndexChange_Command
End Sub
Sub IndexChange_Command(sender As Object, e As EventArgs)
' Display the details of the selected item.
DetailsLabel.Text = "Item Number: " & ItemsGrid.SelectedItem.Cells(1).Text & "<br />" & _
"Description: " & ItemsGrid.SelectedItem.Cells(2).Text & "<br />" & _
"Price: $" & ItemsGrid.SelectedItem.Cells(3).Text & "<br />"
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>Programmatic BaseDataList SelectedIndexChanged Example</h3>
Select an item:
<br /><br />
<asp:DataGrid id="ItemsGrid"
BorderColor="Black"
ShowFooter="False"
CellPadding="3"
CellSpacing="0"
HeaderStyle-BackColor="#aaaadd"
DataKeyField="IntegerValue"
OnSelectedIndexChanged="IndexChange_Command"
runat="server">
<Columns>
<asp:ButtonColumn Text="Select"
CommandName="Select"/>
</Columns>
</asp:DataGrid>
<hr />
<table border="1" style="border-color:Black; margin:0">
<tr style="background-color:#aaaadd">
<td>
Details
</td>
</tr>
<tr>
<td>
<asp:Label id="DetailsLabel"
runat="server"
Text="No item selected."/>
</td>
</tr>
</table>
</form>
</body>
</html>
설명
이 SelectedIndexChanged 이벤트는 서버에 대한 게시물 간의 데이터 목록 컨트롤에서 다른 항목을 선택할 때 발생합니다.
이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.
적용 대상
추가 정보
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET