GridView 删除确认

GridView 删除确认     

<asp:GridView DataKeyNames="CategoryID" ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound" OnRowDeleted="GridView1_RowDeleted" OnRowDeleting="GridView1_RowDeleting">

<Columns>

<asp:BoundField DataField="CategoryID" HeaderText="CategoryID" />

<asp:BoundField DataField="CategoryName" HeaderText="CategoryName" />

<asp:TemplateField HeaderText="Select">

<ItemTemplate>

<asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("CategoryID") %>' CommandName="Delete" runat="server">Delete</asp:LinkButton>

</ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

cs代码:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1");

l.Attributes.Add("onclick", "javascript:return " +

"confirm('Are you sure you want to delete this record " +

DataBinder.Eval(e.Row.DataItem, "CategoryID") + "')");

}

}

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)

{

if (e.CommandName == "Delete")

{

int categoryID = Convert.ToInt32(e.CommandArgument); // get the categoryID of the clicked row

// Delete the record

DeleteRecordByID(categoryID); // Implement this on your own :)

}

}

 

<asp:GridView DataKeyNames="CategoryID" ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound"

 OnRowDeleted="GridView1_RowDeleted" OnRowDeleting="GridView1_RowDeleting">

 

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)

{

int categoryID = (int) GridView1.DataKeys[e.RowIndex].Value;

DeleteRecordByID(categoryID);

}

  
    /// <summary>
    /// 需求计划
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void dv_Result_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[12].Attributes.Add("onclick", "javascript:return confirm('是否确认删除?');");
        }
    }

 其中Cells[12]从0开始,包括隐藏列

<cc2:DataView ID="dv_Result" runat="server" AutoGenerateColumns="False" BackColor="White"
                        BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" Width="841px" CssClass="DataViewControl" HorizontalAlign="Center" OnRowDeleting="dv_Result_RowDeleting"
                        DataKeyNames="NextcheckPersonID" AllowPaging="True" OnPageIndexChanging="dv_Result_PageIndexChanging" OnRowDataBound="dv_Result_RowDataBound">
                        <FooterStyle BackColor="White" ForeColor="#000066" />
                       
                        <Columns>
                            <asp:BoundField DataField="WaitrequireID" HeaderText="计划流水号" />
                            <asp:BoundField DataField="requireDescribe" HeaderText="计划描述" />
                            <asp:BoundField DataField="establishDate" HeaderText="制单时间" />
                            <asp:BoundField DataField="DepartmentName" HeaderText="制单部门"  />
                            <asp:BoundField DataField="establishPersonName" HeaderText="制单人" />
                            <asp:TemplateField HeaderText="编辑">
                                                                                                                   <itemtemplate>
<a href="#" style="text-decoration:underline" οnclick="<%# string.Format("javascript:window.open('RequirementModify.aspx?WaitrequireID={0}','_blank','toolbar=no,height=400px,width=700px,resizable=yes,scrollbars=yes');",Eval("WaitrequireID")) %>" >编辑</a>
                                       
                               
</itemtemplate></asp:TemplateField>
                            <asp:TemplateField HeaderText="查看详情">
                             <itemtemplate>
<a href="#" style="text-decoration:underline" οnclick="<%# string.Format("javascript:window.open('RequirementQueryResult.aspx?WaitrequireID={0}','_blank','toolbar=no,height=400px,width=700px,resizable=yes,scrollbars=yes');",Eval("WaitrequireID")) %>" >查看详情</a>                             
</itemtemplate></asp:TemplateField>
                            <asp:BoundField DataField="spareID" HeaderText="备件编号" Visible="False" />
                            <asp:BoundField DataField="planNum" HeaderText="计划数量" Visible="False" />
                            <asp:BoundField DataField="NextcheckPersonName" HeaderText="下一个审批人" />
                            <asp:TemplateField HeaderText="审批">
                             <itemtemplate>
<a href="#" style="text-decoration:underline" οnclick="<%# string.Format("javascript:window.open('RequireApprove.aspx?WaitrequireID={0}&NextSequence={1}&NextcheckPersonID{2}','_blank','toolbar=no,height=350px,width=600px,resizable=yes,scrollbars=yes');",Eval("WaitrequireID"),Eval("NextSequence"),Eval("NextcheckPersonID")) %>" >审批</a>                              
</itemtemplate></asp:TemplateField> 
                            <asp:TemplateField HeaderText="审批意见">
                             <itemtemplate>
<a href="#" style="text-decoration:underline" οnclick="<%# string.Format("javascript:window.open('ApproveNotionList.aspx?WaitrequireID={0}','_blank','toolbar=no,height=350px,width=600px,resizable=yes,scrollbars=yes');",Eval("WaitrequireID")) %>" >审批意见</a>                               
</itemtemplate></asp:TemplateField>
                            <asp:CommandField HeaderText="删除" ShowDeleteButton="True" />
                        </Columns>
                        <RowStyle ForeColor="#000066" />
                        <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Center" />
                        <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
                <EmptyDataTemplate>
                    <p>
                        <table>
                            <tr>
                                <td style="width: 3px">
                                    <input id="Button2" type="button" value="button" />
                                    <input id="Submit1" type="submit" value="submit" /></td>
                                <td>
                                </td>
                                <td>
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 3px">
                                </td>
                                <td>
                                </td>
                                <td>
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 3px">
                                </td>
                                <td>
                                </td>
                                <td>
                                </td>
                            </tr>
                        </table>
                    </p>
                </EmptyDataTemplate>
              </cc2:DataView>

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值