如何向gridview的DeleteCommand添加警告? [英] how to add a warning to DeleteCommand of gridview?

查看:52
本文介绍了如何向gridview的DeleteCommand添加警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我用VWD做了一个gridview。 gridview的删除按钮设置为

(< asp:CommandField>中的ShowDeleteButton =" True)。

它完美无缺,但我想添加记录之前的警告是

被删除以防止删除错误的记录。

我在代码隐藏文件中这样做:

受保护的子GridView1_RowDeleting(ByVal sender As Object,ByVal e As

System.Web.UI.WebControls.GridViewDeleteEventArgs)句柄

GridView1.RowDeleting

Dim jv作为字符串

jv ="< script language =''javascript''>" _

& "警报(小心!);" _

& if(!confirm(''如果你想删除它,点击OK'')); _

& " {window.location.href = mult.aspx};" _

& "< / script>"

Response.Write(jv)

End Sub


我有效地看到警告,但是当我点击确定或取消

确认时,在这两种情况下都会删除记录。

是否可以防止这种情况,如果是,则如何?


感谢任何提示

Averell

解决方案

2006年5月29日星期一19:00:07 +0200,Averell < AV ***** @ iets.uk>写道:



我用VWD做了一个gridview。 gridview具有删除按钮设置
(< asp:CommandField>中的ShowDeleteButton =" True)。
它完美无缺,但我想在记录之前添加警告我在代码隐藏文件中执行了此操作:
受保护的子GridView1_RowDeleting(ByVal sender As Object,ByVal e As
System.Web.UI。 WebControls.GridViewDeleteEventArgs)句柄
GridView1.RowDeleting
Dim jv As String
jv ="< script language =''javascript''>" _
& "警报(小心!);" _
& if(!confirm(''如果你想删除它,点击OK'')); _
& " {window.location.href = mult.aspx};" _
& "< / script>"
Response.Write(jv)
End Sub

我看到了有效的警告,但当我点击OK或取消
确认,在这两种情况下都会删除记录。
是否可以防止这种情况,如果是,可以如何预防?

感谢任何提示
Averell




您需要返回确认结果。

Peter Kellner
http://peterkellner.net


彼得,我做了一个函数并返回了确认结果,但即使在取消时点击

,该记录也会被删除...

我在''return false'之后插入了一个ALERT而且它不是执行。 Java

代码确实停止了,但是没有删除行的VB代码。


这是正确的方法吗?

谢谢

受保护的子GridView1_RowDeleting(ByVal发送者作为对象,ByVal e As

System.Web.UI.WebControls.GridViewDeleteEventArgs)句柄

GridView1 .RowDeleting

Dim jv As String

jv ="< script language =''javascript''>" _

& function check() _

& " {" _

& " alert(''let op'');" _

& " var ok = confirm(''如果你想删除它,点击OK'');" _

& " if(!ok)" _

& " {" _

& " window.location.href = mult.aspx;" _

& " return false; _

& "警告(''未显示''); _

& "};" _

& "};" _

& "检查();" _

& "< / script>"

Response.Write(jv)

End Sub


" PeterKellner" < PK ********** @ 73rdstreet.com>在消息中写道

news:sd ******************************** @ 4ax.com ...

2006年5月29日星期一19:00:07 +0200,Averell < AV ***** @ iets.uk>写道:



我用VWD做了一个gridview。 gridview具有删除按钮设置
(< asp:CommandField>中的ShowDeleteButton =" True)。
它完美无缺,但我想在记录之前添加警告我在代码隐藏文件中执行了此操作:
受保护的子GridView1_RowDeleting(ByVal sender As Object,ByVal e As
System.Web.UI。 WebControls.GridViewDeleteEventArgs)句柄
GridView1.RowDeleting
Dim jv As String
jv ="< script language =''javascript''>" _
& "警报(小心!);" _
& if(!confirm(''如果你想删除它,点击OK'')); _
& " {window.location.href = mult.aspx};" _
& "< / script>"
Response.Write(jv)
End Sub

我看到了有效的警告,但当我点击OK或取消
确认,在这两种情况下都会删除记录。
是否可以防止这种情况,如果是,可以如何预防?

感谢任何提示
Averell



你需要返回确认结果。
Peter Kellner
http://peterkellner.net



您应该看一下以下示例:

ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_aspnetcon/html/2c688b1a-93a4-4dad-b82b-63974bdbb13e.htm


然后你可以将Page_Load的代码粘贴到你的Row_Deleting事件中

处理程序。

不要忘记默认取消删除!!


Hi,

I made a gridview with VWD. The gridview has the Delete button set
(ShowDeleteButton="True" in the <asp:CommandField>).
It works perfect, but i would like to add a warning before the record is
deleted to prevent deleting a wrong record.
I did this in the code-behind file:
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles
GridView1.RowDeleting
Dim jv As String
jv = "<script language=''javascript''>" _
& " alert(''beware!'');" _
& "if (! confirm(''if you want to delete it, click on OK''));" _
& " {window.location.href=''mult.aspx''};" _
& "</script>"
Response.Write(jv)
End Sub

I see effectively the warning, but when i click on OK or on Cancel of the
Confirm, in both cases the record is deleted.
Is it possible to prevent that, and if yes, how?

Thanks for any hints
Averell

解决方案

On Mon, 29 May 2006 19:00:07 +0200, "Averell" <av*****@iets.uk> wrote:

Hi,

I made a gridview with VWD. The gridview has the Delete button set
(ShowDeleteButton="True" in the <asp:CommandField>).
It works perfect, but i would like to add a warning before the record is
deleted to prevent deleting a wrong record.
I did this in the code-behind file:
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewDeleteEventArgs ) Handles
GridView1.RowDeleting
Dim jv As String
jv = "<script language=''javascript''>" _
& " alert(''beware!'');" _
& "if (! confirm(''if you want to delete it, click on OK''));" _
& " {window.location.href=''mult.aspx''};" _
& "</script>"
Response.Write(jv)
End Sub

I see effectively the warning, but when i click on OK or on Cancel of the
Confirm, in both cases the record is deleted.
Is it possible to prevent that, and if yes, how?

Thanks for any hints
Averell



You need to return the results of confirm.
Peter Kellner
http://peterkellner.net


Peter, i made a function and returned the confirm result, but even clicking
on Cancel, the record is deleted ...
I inserted an ALERT after the ''return false'' and it''s not executed. The Java
code stops indeed, but not the VB code deleting the row.

Is this the right way to proceed?
thanks
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles
GridView1.RowDeleting
Dim jv As String
jv = "<script language=''javascript''>" _
& "function check()" _
& "{" _
& " alert(''let op'');" _
& " var ok=confirm(''if you want to delete it, click on OK'');" _
& " if (!ok)" _
& " {" _
& " window.location.href=''mult.aspx'';" _
& " return false;" _
& " alert(''this is not shown'');" _
& "};" _
& "};" _
& "check();" _
& "</script>"
Response.Write(jv)
End Sub

"PeterKellner" <pk**********@73rdstreet.com> wrote in message
news:sd********************************@4ax.com...

On Mon, 29 May 2006 19:00:07 +0200, "Averell" <av*****@iets.uk> wrote:

Hi,

I made a gridview with VWD. The gridview has the Delete button set
(ShowDeleteButton="True" in the <asp:CommandField>).
It works perfect, but i would like to add a warning before the record is
deleted to prevent deleting a wrong record.
I did this in the code-behind file:
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewDeleteEventArgs ) Handles
GridView1.RowDeleting
Dim jv As String
jv = "<script language=''javascript''>" _
& " alert(''beware!'');" _
& "if (! confirm(''if you want to delete it, click on OK''));" _
& " {window.location.href=''mult.aspx''};" _
& "</script>"
Response.Write(jv)
End Sub

I see effectively the warning, but when i click on OK or on Cancel of the
Confirm, in both cases the record is deleted.
Is it possible to prevent that, and if yes, how?

Thanks for any hints
Averell



You need to return the results of confirm.
Peter Kellner
http://peterkellner.net



You should look the example at :
ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_aspnetcon/html/2c688b1a-93a4-4dad-b82b-63974bdbb13e.htm

Then you might paste the code of Page_Load into your Row_Deleting event
handler.
Don''t forget to Cancel delete by default !!


这篇关于如何向gridview的DeleteCommand添加警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆