CommandField.NewText 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置 CommandField 字段中的“新建”按钮的标题。
public:
virtual property System::String ^ NewText { System::String ^ get(); void set(System::String ^ value); };
public virtual string NewText { get; set; }
member this.NewText : string with get, set
Public Overridable Property NewText As String
属性值
CommandField 字段中的“新建”按钮的标题。 默认值为“New”。
示例
下面的代码示例演示如何使用 NewText 属性为控件字段中CommandFieldDetailsView显示的“新建”按钮指定自定义标题。
<%@ Page language="C#" %>
<!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>CommandField Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>CommandField Example</h3>
<asp:detailsview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneraterows="false"
datakeynames="CustomerID"
allowpaging="true"
runat="server">
<fields>
<asp:boundfield datafield="CustomerID"
headertext="Customer ID" />
<asp:boundfield datafield="CompanyName"
headertext="CompanyName"/>
<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"/>
<asp:commandfield showinsertbutton="true"
inserttext="Save"
newtext="Add New Customer"
showheader="true"
headertext="Add Customer"/>
</fields>
</asp:detailsview>
<!-- 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]"
insertcommand="Insert Into [Customers]([CustomerID], [CompanyName], [City], [PostalCode], [Country]) Values (@CustomerID, @CompanyName, @City, @PostalCode, @Country)"
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">
<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:detailsview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneraterows="false"
datakeynames="CustomerID"
allowpaging="true"
runat="server">
<fields>
<asp:boundfield datafield="CustomerID"
headertext="Customer ID" />
<asp:boundfield datafield="CompanyName"
headertext="CompanyName"/>
<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"/>
<asp:commandfield showinsertbutton="true"
inserttext="Save"
newtext="Add New Customer"
showheader="true"
headertext="Add Customer"/>
</fields>
</asp:detailsview>
<!-- 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]"
insertcommand="Insert Into [Customers]([CustomerID], [CompanyName], [City], [PostalCode], [Country]) Values (@CustomerID, @CompanyName, @City, @PostalCode, @Country)"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
注解
ButtonType当 对象的 属性CommandField设置为 ButtonType.Button
或 ButtonType.Link
时,NewText使用 属性指定要为“新建”按钮显示的文本。
注意
作为显示“新建”按钮文本的替代方法,可以先将 属性ButtonType.Image
设置为 ButtonType ,然后设置 NewImageUrl 属性来显示图像。
设置此属性的值时,可以使用设计器工具自动保存到资源文件。 有关详细信息,请参阅 LocalizableAttribute 和 全球化和本地化。