CommandField.ShowSelectButton 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示是否在 CommandField 字段中显示“选择”按钮。
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
属性值
如果在 CommandField 中显示“选择”按钮,则为 true
;否则为 false
。 默认值为 false
。
示例
下面的代码示例演示如何使用 ShowSelectButton 属性显示 控件中每条记录的 GridView “选择”按钮。
<%@ 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>
注解
ShowSelectButton使用 属性指定是否在数据源控件中每条CommandField记录的字段中显示“选择”按钮。 “选择”按钮允许用户在数据源控件中选择一行。 单击记录的“选择”按钮时,数据源控件会做出相应的响应。 例如,控件 GridView 将 SelectedDataKey、 SelectedIndex、 SelectedRow和 SelectedValue 属性更新为与所选行对应的值。 然后,该 SelectedRowStyle 样式将应用于所选行, SelectedIndexChanged 并引发 和 SelectedIndexChanging 事件。
ButtonType当字段的 CommandField 属性设置为 ButtonType.Button
或 ButtonType.Link
时,SelectText使用 属性指定要为“选择”按钮显示的文本。 或者,可以通过先将 ButtonType 属性设置为 ButtonType.Image
,然后设置 SelectImageUrl 属性来显示图像。