CommandField.NewImageUrl 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置为 CommandField 字段中的“新建”按钮显示的图像的 URL。
public:
virtual property System::String ^ NewImageUrl { System::String ^ get(); void set(System::String ^ value); };
public virtual string NewImageUrl { get; set; }
member this.NewImageUrl : string with get, set
Public Overridable Property NewImageUrl As String
属性值
为 CommandField 中的“新建”按钮显示的图像的 URL。 默认值为空字符串 (""),表示尚未设置此属性。
示例
下面的代码示例演示如何使用NewImageUrl属性指定要为控件的列字段中DetailsView的“新建”按钮CommandField显示的自定义图像。 ButtonType属性必须设置为ButtonType.Image
“新建”按钮才能显示图像。
<%@ 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"
buttontype="Image"
insertimageurl="~\Images\InsertButton.jpg"
newimageurl="~\Images\AddButton.jpg"
cancelimageurl="~\Images\CancelButton.jpg"
showheader="true"
headertext="Add Store"/>
</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="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"
buttontype="Image"
insertimageurl="~\Images\InsertButton.jpg"
newimageurl="~\Images\AddButton.jpg"
cancelimageurl="~\Images\CancelButton.jpg"
showheader="true"
headertext="Add Store"/>
</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.Image
时,请使用NewImageUrl该属性指定要为“新建”按钮显示的图像。 只要客户端的浏览器支持该格式,此图像就可以采用任何文件格式 (.jpg、.gif、.bmp 等) 。
备注
作为显示“新建”按钮图像的替代方法,可以通过先将ButtonType属性设置为或ButtonType.Link
设置NewText属性ButtonType.Button
来显示文本。