レコードを削除するための削除リンクを持つ GridView があります。DeleteButtonField クラスを作成しましたが、テキストを画像 (アイコン) に置き換えたいと考えています。これは可能ですか?これが私のGridViewです:
<asp:GridView
ID="GridView1"
runat="server"
<.. removed dome properties ..>
>
<Columns>
<CustomControls:DeleteButtonField ConfirmText="Delete this record?" />
<.. other columns ..>
</Columns>
</asp:GridView>
ここに私の DeleteButtonField クラスがあります:
using System;
using System.Web.UI.WebControls;
namespace CustomControls
{
public class DeleteButtonField : ButtonField
{
private string _confirmText = "Delete this record?";
public string ConfirmText
{
get { return _confirmText; }
set { _confirmText = value; }
}
public DeleteButtonField()
{
this.CommandName = "Delete";
this.Text = "Delete";
this.ImageUrl = "App_GlobalResources/Del.png"; // doesn't work
}
public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
{
base.InitializeCell(cell, cellType, rowState, rowIndex);
if (cellType == DataControlCellType.DataCell)
{
WebControl button = (WebControl)cell.Controls[0];
button.Attributes["onclick"] = String.Format("return confirm('{0}');", _confirmText);
}
}
}
}
これは可能ですか?ご覧のとおり、次のコードを DeleteButtonField.cs クラスに追加しましたが、効果はありませんでした。this.ImageUrl = "App_GlobalResources/Del.png";
ありがとう。