CommandField.ShowSelectButton Eigenschaft
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Dient zum Abrufen oder Festlegen eines Werts, der angibt, ob eine Auswahlschaltfläche in einem CommandField Feld angezeigt wird.
public:
virtual property bool ShowSelectButton { bool get(); void set(bool value); };
public virtual bool ShowSelectButton { get; set; }
member this.ShowSelectButton : bool with get, set
Public Overridable Property ShowSelectButton As Boolean
Eigenschaftswert
true zum Anzeigen einer Select-Schaltfläche in einem CommandField; andernfalls false. Der Standardwert lautet false.
Beispiele
Im folgenden Codebeispiel wird veranschaulicht, wie die ShowSelectButton Eigenschaft zum Anzeigen einer Auswahlschaltfläche für jeden Datensatz in einem GridView Steuerelement verwendet wird.
<%@ 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)
{
// Retrieve the company name from the appropriate cell.
String companyName = CustomersGridView.SelectedRow.Cells[2].Text;
// Display company name selected by the user.
Message.Text = "You selected " + companyName + ".";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>CommandField Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>CommandField Example</h3>
<asp:Label id="Message"
forecolor="Red"
runat="server"/>
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="false"
datakeynames="CustomerID"
onselectedindexchanged="CustomersGridView_SelectedIndexChanged"
runat="server">
<columns>
<asp:commandfield showselectbutton="true"
headertext="Select Customer"/>
<asp:boundfield datafield="CustomerID"
headertext="Customer ID" />
<asp:boundfield datafield="CompanyName"
headertext="Company Name"/>
<asp:boundfield datafield="Address"
headertext="Address"/>
<asp:boundfield datafield="City"
headertext="City"/>
<asp:boundfield datafield="PostalCode"
headertext="ZIP Code"/>
<asp:boundfield datafield="Country"
headertext="Country"/>
</columns>
</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]"
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_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles CustomersGridView.SelectedIndexChanged
' Retrieve the company name from the appropriate cell.
Dim companyName As String = CustomersGridView.SelectedRow.Cells(2).Text
' Display company name selected by the user.
Message.Text = "You selected " & companyName & "."
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>CommandField Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>CommandField Example</h3>
<asp:Label id="Message"
forecolor="Red"
runat="server"/>
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="false"
datakeynames="CustomerID"
runat="server">
<columns>
<asp:commandfield showselectbutton="true"
headertext="Select Customer"/>
<asp:boundfield datafield="CustomerID"
headertext="Customer ID" />
<asp:boundfield datafield="CompanyName"
headertext="Company Name"/>
<asp:boundfield datafield="Address"
headertext="Address"/>
<asp:boundfield datafield="City"
headertext="City"/>
<asp:boundfield datafield="PostalCode"
headertext="ZIP Code"/>
<asp:boundfield datafield="Country"
headertext="Country"/>
</columns>
</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]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
Hinweise
Verwenden Sie die ShowSelectButton Eigenschaft, um anzugeben, ob eine Select-Schaltfläche in einem CommandField Feld für jeden Datensatz im Datenquellensteuerelement angezeigt wird. Mit der Schaltfläche "Auswählen" kann der Benutzer eine Zeile im Datenquellensteuerelement auswählen. Wenn auf die Schaltfläche "Auswählen" für einen Datensatz geklickt wird, reagiert das Datenquellensteuerelement entsprechend. Ein Steuerelement aktualisiert z. BGridView. die WerteSelectedRowSelectedIndex, die SelectedDataKeyder ausgewählten Zeile entsprechen, und SelectedValue die Eigenschaften. Die SelectedRowStyle Formatvorlage wird dann auf die ausgewählte Zeile angewendet, und die SelectedIndexChanged Ereignisse SelectedIndexChanging werden ausgelöst.
Wenn die ButtonType Eigenschaft eines CommandField Felds auf ButtonType.Button oder ButtonType.Link, verwenden Sie die SelectText Eigenschaft, um den Text anzugeben, der für eine Auswahlschaltfläche angezeigt werden soll. Alternativ können Sie ein Bild anzeigen, indem Sie zuerst die ButtonType Eigenschaft auf ButtonType.Image und dann die SelectImageUrl Eigenschaft festlegen.