GridView.SelectedValue Ö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.
Denetimde seçili satırın GridView veri anahtarı değerini alır.
public:
property System::Object ^ SelectedValue { System::Object ^ get(); };
[System.ComponentModel.Browsable(false)]
public object SelectedValue { get; }
[<System.ComponentModel.Browsable(false)>]
member this.SelectedValue : obj
Public ReadOnly Property SelectedValue As Object
Özellik Değeri
Denetimdeki seçili satırın GridView veri anahtarı değeri.
- Öznitelikler
Örnekler
Aşağıdaki örnekte, bir denetimde seçili satırın SelectedValueGridView veri anahtarı değerini 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_SelectedIndexChanged(Object sender, EventArgs e)
{
// Display the primary key value of the selected row.
Message.Text = "The primary key value of the selected row is " +
CustomersGridView.SelectedValue.ToString() + ".";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridView SelectedValue Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridView SelectedValue Example</h3>
<asp:label id="Message"
forecolor="Red"
runat="server"/>
<br/><br/>
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSource"
allowpaging="true"
autogeneratecolumns="true"
autogenerateselectbutton="true"
datakeynames="CustomerID"
onselectedindexchanged="CustomersGridView_SelectedIndexChanged"
runat="server">
<selectedrowstyle backcolor="LightBlue"
forecolor="DarkBlue"/>
</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="CustomersSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
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 CustomersGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
' Display the primary key value of the selected row.
Message.Text = "The primary key value of the selected row is " & _
CustomersGridView.SelectedValue.ToString() & "."
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridView SelectedValue Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridView SelectedValue Example</h3>
<asp:label id="Message"
forecolor="Red"
runat="server"/>
<br/><br/>
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSource"
allowpaging="true"
autogeneratecolumns="true"
autogenerateselectbutton="true"
datakeynames="CustomerID"
onselectedindexchanged="CustomersGridView_SelectedIndexChanged"
runat="server">
<selectedrowstyle backcolor="LightBlue"
forecolor="DarkBlue"/>
</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="CustomersSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</form>
</body>
</html>
Açıklamalar
Özellik, veri kaynağının DataKeyNames birincil anahtarını temsil eden alan adlarının virgülle ayrılmış listesiyle ayarlandığında, GridView denetim, belirtilen alan veya alanların değerini veya değerlerini kullanarak denetimdeki her satır için otomatik olarak bir DataKey nesne oluşturur. Ardından DataKey nesneler denetimin DataKeys koleksiyonuna eklenir. Normalde özelliği, denetimdeki DataKeys belirli bir veri satırının DataKeyGridView nesnesini almak için kullanılır. Ancak, yalnızca seçili durumdaki satırın DataKey nesnesini almanız gerekiyorsa, özelliği kısayol olarak kullanabilirsiniz SelectedDataKey . Daha fazla kısayol olarak, özelliğini kullanarak SelectedValue seçili satırın ilk anahtar alanının veri anahtarı değerini doğrudan belirleyebilirsiniz.
Bir ControlParameter nesne oluşturuyorsanız ve ilk alan dışında bir anahtar alanına erişmek istiyorsanız özelliğini kullanın SelectedDataKey . Bir örnek için bkz. SelectedDataKey.