在gridview中用向导加入了一个commandfield 的删除按钮。 用的buttontype是image。后台代码如下
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack() Then
bindDataGrid()
End If
End Sub
Private Sub bindDataGrid()
Dim indexs(0 To 0) As String
indexs(0) = "公告ID"
cnn = New SqlConnection(strCnn)
cnn.Open()
Dim cmdStr As String = "select * from 技术公告 order by 发布日期 desc"
dad = New SqlDataAdapter(cmdStr, cnn)
dst = New DataSet()
dad.Fill(dst, "all")
GridView1.DataSource = dst.Tables("all").DefaultView()
GridView1.DataKeyNames = indexs
GridView1.DataBind()
cnn.Close()
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
If (e.Row.RowState = DataControlRowState.Normal Or e.Row.RowState = DataControlRowState.Alternate) Then
Dim aa As WebControls.ImageButton
Dim returnValue As Type
returnValue = e.Row.Cells(1).Controls(0).GetType()
aa = e.Row.Cells(1).Controls(0)
aa.Attributes.Add("onclick", "return confirm('你确定删除吗?')") End If
End If
End Sub Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting Dim selKeyIndex As String selKeyIndex = Convert.ToInt32(GridView1.DataKeys(e.RowIndex()).Value.ToString())
'开始删除
cnn = New SqlConnection(strCnn)
cmd = New SqlCommand("delete 技术公告 where 公告ID=" & selKeyIndex, cnn)
cnn.Open()
cmd.ExecuteNonQuery()
cnn.Close()
bindDataGrid() End Sub
End Class执行后确认框是出来了 但是无论点击“是” “否”都不进入GridView1_RowDeleting 函数。 直接进入page_load 函数了,原来没加确认对话框是反而好使 ,一加就不行了 咋回事啊?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack() Then
bindDataGrid()
End If
End Sub
Private Sub bindDataGrid()
Dim indexs(0 To 0) As String
indexs(0) = "公告ID"
cnn = New SqlConnection(strCnn)
cnn.Open()
Dim cmdStr As String = "select * from 技术公告 order by 发布日期 desc"
dad = New SqlDataAdapter(cmdStr, cnn)
dst = New DataSet()
dad.Fill(dst, "all")
GridView1.DataSource = dst.Tables("all").DefaultView()
GridView1.DataKeyNames = indexs
GridView1.DataBind()
cnn.Close()
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
If (e.Row.RowState = DataControlRowState.Normal Or e.Row.RowState = DataControlRowState.Alternate) Then
Dim aa As WebControls.ImageButton
Dim returnValue As Type
returnValue = e.Row.Cells(1).Controls(0).GetType()
aa = e.Row.Cells(1).Controls(0)
aa.Attributes.Add("onclick", "return confirm('你确定删除吗?')") End If
End If
End Sub Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting Dim selKeyIndex As String selKeyIndex = Convert.ToInt32(GridView1.DataKeys(e.RowIndex()).Value.ToString())
'开始删除
cnn = New SqlConnection(strCnn)
cmd = New SqlCommand("delete 技术公告 where 公告ID=" & selKeyIndex, cnn)
cnn.Open()
cmd.ExecuteNonQuery()
cnn.Close()
bindDataGrid() End Sub
End Class执行后确认框是出来了 但是无论点击“是” “否”都不进入GridView1_RowDeleting 函数。 直接进入page_load 函数了,原来没加确认对话框是反而好使 ,一加就不行了 咋回事啊?
解决方案 »
- 页面传值
- 请问如何统计某个页面的在线人数?
- 用devexpress dotnet 7.3 使用PivotGrid,求和时,不能汇总,设置要汇总的属性的TotalsVisibility设成Automatic
- 请教什么是镜像网站?如何配置?
- 分隔连接字符传,在线等,帮忙
- !!!我很菜 超简单问题!!! 进来告诉我就给你
- 在服务器端有没有类似window.document.body.innerHTML的功能
- 如果我的输入焦点在一个textbox时候,按回车键就执行一个后代码里的函数,我该如何实现呀???
- 怎么判断上传的图片的长和宽尺寸,以及文件大小?-------------------------------------------
- 求助。我数据库用access,如何通过按钮修改数据库信息
- 怎么解决用OWC通过访问OLAP数据库的N个问题?
- 正则:匹配HTML标识外的非链接内的指定字符
为 aa.OnClientClick = "return confirm('你确定删除吗?');"最好看看生成的html代碼是否正確
但是还是不明白 aa.Attributes.Add("onclick", "if(!confirm('你确定删除吗?')) return false") 和
aa.Attributes.Add("onclick", "return confirm('你确定删除吗?')")
有什么区别? aspnet2.0和1.1还是有差别啊
__doPostBack(...)这样的代码,也就是说后面有些东西你控制不了,所以改成幕白兄 的这种方式就ok了
aa.Attributes.Add("onclick", "return confirm('你确定删除吗?')")
--------------------------------------
javascript语句运行顺序的问题。.net控件的提交用的也是 onclick 事件,试想,如果return confirm('你确定删除吗?');要是先于其他代码运行了,其他的代码还会有效吗?使用if(!confirm('你确定删除吗?')) return false;是一种非常好的习惯!