GridViewDeleteEventArgs.RowIndex Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Silinen satırın dizinini alır.
public:
property int RowIndex { int get(); };
public int RowIndex { get; }
member this.RowIndex : int
Public ReadOnly Property RowIndex As Integer
Özellik Değeri
Silinen satırın sıfır tabanlı dizini.
Örnekler
Aşağıdaki örnekte, silinecek satırın dizinini RowIndex belirlemek için özelliğinin nasıl kullanılacağı gösterilmektedir.
<%@ 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 CustomersGridView_RowDeleting(Object sender, GridViewDeleteEventArgs e)
{
// Get the country/region of the record being deleted.
GridViewRow row = CustomersGridView.Rows[e.RowIndex];
String region = row.Cells[6].Text;
// Cancel the delete operation if the country/region is "USA".
if(region == "USA")
{
e.Cancel = true;
Message.Text = "You cannot delete a record from " + region + ".";
}
}
void CustomersGridView_RowDeleted(Object sender, GridViewDeletedEventArgs e)
{
if (e.Exception == null)
{
// The delete operation succeeded. Clear the message label.
Message.Text = "";
}
else
{
// The delete operation failed. Display an error message.
Message.Text = "An error occurred during the delete operation. " +
e.AffectedRows.ToString() + " rows deleted.";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridViewDeleteEventArgs RowIndex Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridViewDeleteEventArgs RowIndex Example</h3>
<asp:label id="Message"
forecolor="Red"
runat="server"/>
<br/>
<asp:gridview id="CustomersGridView"
allowpaging="true"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="true"
autogeneratedeletebutton="true"
datakeynames="CustomerID"
onrowdeleted="CustomersGridView_RowDeleted"
onrowdeleting="CustomersGridView_RowDeleting"
runat="server">
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:sqldatasource id="CustomersSqlDataSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
deletecommand="Delete from Customers where CustomerID = @CustomerID"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
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 CustomersGridView_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)
' Get the country/region of the record being deleted.
Dim row As GridViewRow = CustomersGridView.Rows(e.RowIndex)
Dim region As String = row.Cells(6).Text
' Cancel the delete operation if the country/region is "USA".
If region = "USA" Then
e.Cancel = True
Message.Text = "You cannot delete a record from " & region & "."
End If
End Sub
Sub CustomersGridView_RowDeleted(ByVal sender As Object, ByVal e As GridViewDeletedEventArgs)
If e.Exception Is Nothing Then
' The delete operation succeeded. Clear the message label.
Message.Text = ""
Else
' The delete operation failed. Display an error message.
Message.Text = "An error occurred during the delete operation. " & _
e.AffectedRows.ToString() & " rows deleted."
e.ExceptionHandled = true
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridViewDeleteEventArgs RowIndex Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridViewDeleteEventArgs RowIndex Example</h3>
<asp:label id="Message"
forecolor="Red"
runat="server"/>
<br/>
<asp:gridview id="CustomersGridView"
allowpaging="true"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="true"
autogeneratedeletebutton="true"
datakeynames="CustomerID"
onrowdeleted="CustomersGridView_RowDeleted"
onrowdeleting="CustomersGridView_RowDeleting"
runat="server">
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:sqldatasource id="CustomersSqlDataSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
deletecommand="Delete from Customers where CustomerID = @CustomerID"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
Açıklamalar
Satır dizini genellikle denetimin koleksiyonundan RowsGridView belirtilen satırı almak için kullanılır. Daha sonra satırın özelliklerine erişebilirsiniz.
Şunlara uygulanır
Ayrıca bkz.
GitHub'da bizimle işbirliği yapın
Bu içeriğin kaynağı GitHub'da bulunabilir; burada ayrıca sorunları ve çekme isteklerini oluşturup gözden geçirebilirsiniz. Daha fazla bilgi için katkıda bulunan kılavuzumuzu inceleyin.