私はレコードを削除するには、[削除]リンクを持っているのGridViewを持っています。私はDeleteButtonFieldクラスを作成しましたが、テキストをイメージ(アイコン)に置き換えたいと思います。これは可能ですか?ここに私のGridViewです:ButtonFieldを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";
感謝。
@Brian、私は問題を抱えています。イメージをクリックするとレコードが削除されることはありません。あなたは何が間違っているかも知っていますか? –
Mark、上記のコードを見てください。今すぐ働かなければならない。もともと私はあなたのためにTemplateFieldの例を書くつもりだったので、私は私の銃に立ち往生すべきです。それは物事をより良く扱う(ポストバックなど)。 :) –
@ブライアン、ありがとう。これを実行すると、ASP.NET開発Webサーバーがクラッシュします。 –