在GridView中点击图片,先跳出确认框,再调用服务器端代码问题(哪位大侠能解决阿)
aspx代码:
<asp:GridView ID= "gv_ExpressInterestDocuments " runat= "server " Width= "100% " AutoGenerateColumns= "False " BorderWidth= "0px " DataKeyNames= "Id "OnRowDeleting= "gv_ExpressInterestDocuments_RowDeleting ">
<Columns>
<asp:CommandField ButtonType= "Image " DeleteImageUrl= "~/imgs/esrcGarbageCan.GIF " ShowDeleteButton= "True " >
<ItemStyle HorizontalAlign= "Center " VerticalAlign= "Middle " Width= "30px " />
</asp:CommandField>
<asp:BoundField DataField= "Id " Visible= "False " />
<asp:TemplateField HeaderText= "Document Title ">
<HeaderStyle CssClass= "tabTitle " />
<ItemStyle Width= "200px " />
<ItemTemplate>
<asp:LinkButton ID= "LinkButton1 " runat= "server " OnCommand= "Update " Text= ' <%#DataBinder.Eval(Container.DataItem, "FileName ")%> '
CommandArgument= ' <%#DataBinder.Eval(Container.DataItem, "FilePath ")%> '> LinkButton </asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField>
<ItemStyle Width= "1% " />
</asp:BoundField>
<asp:BoundField HeaderText= "UploadedDate "DataField= "UploadedDate ">
<HeaderStyle CssClass= "tabTitle " />
</asp:BoundField>
</Columns>
</asp:GridView>
原先是在GridView点击esrcGarbageCan.GIF图片调用服务器段gv_ExpressInterestDocuments_RowDeleting方法删除这一列,现在要求点击这个图片之后先弹出一个确认框confirm,确认之后再调用服务器端方法删除这一列,哪位大侠救命啊,告诉我怎么实现,立马给分谢谢!
[解决办法]
//aspx页面注册RowDataBound事件
<asp:GridView ID= "GridView1 " runat= "server " OnRowDataBound= "GridView1_RowDataBound " ...>
//aspx.cs代码
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton l = (ImageButton)e.Row.Cells[0].Controls[0];
l.Attributes.Add( "onclick ", "return confirm( '确定删除第 " + (e.Row.RowIndex + 1) + "项? '); ");
}
}