1.在RowDateBound事件中添加:
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
        {          
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
                {
                    ((LinkButton)e.Row.Cells[1].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除名称为:\"" + e.Row.Cells[3].Text.ToString().Trim() + "\" 的票据类型吗?')");
                }
            }
        }


2.转为模板列,在前台直接添加:
<asp:TemplateField HeaderText="删除" ShowHeader="False">
                        <ItemTemplate>
                            <asp:ImageButton ID="ImageButton10" runat="server"
                            OnClientClick="javascript:return confirm('您是否确认要删除选定的送货单?');"
                             CommandName="Delete" CausesValidation="False"
                                ImageUrl="~/images/Gridview_Delete/record_delete_16x16.gif" />
                        </ItemTemplate>
                    </asp:TemplateField>

 

 

 

对比DataGrid

  protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                LinkButton lb = (LinkButton)e.Item.Cells[4].Controls[0];
                lb.Attributes.Add("onclick", "javascript:if(!window.confirm('Delete,YES or NO ?')) return false;");
            }
        }

 

posted on 2010-09-30 10:36  使名扬  阅读(236)  评论(0编辑  收藏  举报