GridView 模板字段确认框

GridView TemplateField Confirmation Box

我正在使用内部带有超链接的 gridview 进行回发以删除一些数据,这是我的代码

<asp:GridView ID="downloadFilesTable" runat="server" BorderStyle="Solid"
    AutoGenerateColumns="False" DataKeyNames="DOCID" 
    DataSourceID="SqlDataSource1" 
    OnSelectedIndexChanged="downloadFilesTable_SelectedIndexChanged">
    <Columns>
        <asp:BoundField DataField="DOCID" HeaderText="DOCID" InsertVisible="False" ReadOnly="True" SortExpression="DOCID" />
        <asp:BoundField DataField="FILENAME" HeaderText="FILENAME" SortExpression="FILENAME" />
        <asp:BoundField DataField="EXTENSION" HeaderText="EXTENSION" SortExpression="EXTENSION" />
        <asp:HyperLinkField  
            DataNavigateUrlFields="DOCID"
            DataNavigateUrlFormatString="DownloadFile.aspx?id={0}"
            HeaderText="File" 
            Text="Open" />
        <asp:TemplateField HeaderText="File">
            <ItemTemplate>
                <asp:HyperLink runat="server" 
                    NavigateUrl='<%# "~/ViewDocument.aspx?table="
                        + Request.QueryString["table"].ToString() 
                        + "&id=" + Request.QueryString["id"].ToString() 
                        + "&docid=" + Request.QueryString["docid"].ToString() 
                        + "&remove=" + Server.UrlEncode(Eval("docid").ToString())%>' 
                    datanavigateurlfields="docid" 
                    HeaderText="File" 
                    Text="Remove" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

用户将单击 ItemTemplate 超链接以删除数据,但问题是,当我要删除数据时,我需要一个确认框,如果用户单击是,我将删除数据,这是一个gridview 因为我认为我无法访问 onclick 函数,有什么线索吗? (例如,在服务器端执行?)非常感谢您的帮助,在此先感谢!

更好 你可以使用弹出窗口 window 并做一些设计

  <html>
 <head runat="server">
<title></title>
 <link href="CSS/LoginPage.css" type="text/css" rel="Stylesheet" />
<link href="CSS/ModalPopup.css" type="text/css" rel="Stylesheet" />

<style type="text/css">
    .style1
    {
        height: 139px;
    }
    .style2
    {
        width: 298px;
    }
    .style3
    {
        height: 62px;
    }
    .style4
    {
        width: 298px;
        height: 62px;
    }
    .style5
    {
        width: 572px;
    }
    .style6
    {
        width: 572px;
        height: 62px;
    }
</style>
<script language="javascript" type="text/javascript">
</script>
     </head>
     <body>
      <form id="form1" runat="server">
     <table cellpadding="0" cellspacing="0" align="center" 
          style="height: 138px; width: 375px; position: absolute; top: 0px; left: 0px;">
            <tr>
                <td  align="center" id="tdsave" runat="server" class="style1">


                            <div class="ModalDragHeader">
                                <table style="border: thin solid #6FB1E3; width: 376px" >
                                    <tr>
                                        <td  
                                            style="font-family: arial, Helvetica, sans-serif; font-size: medium; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #FFFFFF;">
                                            Bluekode</td>
                                        <td class="style5">
                                            </td>
                                        <td class="style2">
                                            &nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td class="style3" >
                                            <asp:Image ID="imgmsg" runat="server" Height="45px" Width="64px" /></td>
                                        <td  

                                            style="font-family: arial, Helvetica, sans-serif; color: #000000; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none;" 
                                            class="style6">
                                          <asp:Label ID="LSave" runat="server" Font-Names="arial" Font-Size="Large">You want to delete?</asp:Label></td>
                                        <td  

                                            style="font-family: arial, Helvetica, sans-serif; color: #000000; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none;" 
                                            class="style4">
                                            </td>
                                    </tr>
                                    <tr>
                                        <td >
                                           </td>
                                        <td id="btnbtnok" runat="server">

                                                <asp:Button ID="btnok" runat="server" CssClass="buttonL"  Text="yes" Width="60px" 
                                                    Height="24px" />



                                                <asp:Button ID="btnok0" runat="server" CssClass="buttonL"  Text="no" Width="60px" 
                                                    Height="24px" />

                                        </td>
                                        <td >
                                           </td>
                                    </tr>

                                </table>
                            </div>


                </td>
            </tr>
        </table>
</form>

在你的屏幕上使用会话并传递它

在你的页面上

<script language="javascript" type="text/javascript">
function myFunction() {
    window.open("msgbx.aspx", "_blank", "toolbar=yes,scrollbars=no,resizable=yes,top=100,left=200,width=250,height=200");
}

在 link 按钮上

        <var><button onclick="myFunction()" text="Delete"</button> </var>

每次加载网格时,它都会一次加载一行,并且有一个您可以使用的名为 RowDataBound 的事件。

将控件更改为 LinkBut​​ton,因为它有 OnClientClick 事件。

protected void gvw_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow) 
    {
        // reference the Delete button. (i think it's cell 4.)
        LinkButton lbtn = (LinkButton)e.Row.Cells[4].Controls[0]; 

        lbtn.OnClientClick = "return confirm('Are you certain you want to delete?');"
    }
}