我正在使用带有超链接的网格视图进行回发,以删除一些数据,这是我的代码
<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超链接删除数据,但问题是,当我想删除数据时,我想要一个确认框,如果用户单击“是”,我将删除数据,这是一个网格视图,因为我认为我无法访问onclick函数,有任何线索吗?(为前任。在服务器端做什么?)每一个帮助都是非常感谢的,谢谢提前!
发布于 2018-04-03 04:56:00
每次网格加载时,它都一次加载一行,并有一个您可以使用的事件,称为RowDataBound。
将控件更改为LinkButton,因为它有一个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?');"
}
}发布于 2018-04-03 04:32:24
更好的是你可以用一个弹出窗口做一些设计。
<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">
</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");
}on link button <var><button onclick="myFunction()" text="Delete"</button> </var>https://stackoverflow.com/questions/49622169
复制相似问题