标题:一个关于删除的提示的问题,
只看楼主
guyer
Rank: 2
等 级:新手上路
威 望:5
帖 子:451
专家分:0
注 册:2007-1-19
 问题点数:0 回复次数:1 
一个关于删除的提示的问题,

Imports System.Web
Imports System.Collections
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Web.UI.WebControls

Public Class master
Inherits System.Web.UI.Page
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents myDataGrid As System.Web.UI.WebControls.DataGrid
'#Region " Web 窗体设计器生成的代码 "
' '该调用是 Web 窗体设计器所必需的。
' <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
' End Sub
' Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
' 'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
' '不要使用代码编辑器修改它。
' InitializeComponent()
' End Sub
'#End Region


#Region " Web 窗体设计器生成的代码 "

'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm

'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myDataGrid.HeaderStyle.Font.Bold = True
myDataGrid.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
myDataGrid.Columns(0).HeaderText = "用户名"
myDataGrid.Columns(1).HeaderText = "操作"
If Not IsPostBack Then
Dim strCn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("datebase/db.mdb")
Dim strSql As String
strSql = "SELECT Top 15 id,users FROM adminuser Order By id Desc"
Dim cn As New OleDbConnection(strCn)
cn.Open()
Dim cmd As New OleDbCommand(strSql, cn)
myDataGrid.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)
myDataGrid.DataBind()
cmd.Dispose()
cmd = Nothing
cn.Close()
cn.Dispose()
cn = Nothing
End If


End Sub

Sub DataGrid_ItemCreated(ByVal Sender As Object, ByVal e As DataGridItemEventArgs) Handles myDataGrid.ItemCreated
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem, ListItemType.EditItem
Dim myDeleteButton As Button
myDeleteButton = e.Item.FindControl("btnDelete")
myDeleteButton.Text = "删除"
'myDeleteButton.Attributes.Add("onclick", "return confirm('您真的要删除第" + Str(Int(e.Item.ItemIndex.ToString) + 1) + " 行吗?');")
myDeleteButton.Attributes.Add("onclick", "return confirm('您真的要删除 " + e.Item.DataItem("users") + " 用户?');")

End Select
End Sub
Private Sub myDataGrid_ItemCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles myDataGrid.ItemCommand
Response.Write("您要删除的是:<font color=red>" + e.Item.Cells(0).Text + "</font>")
'
'e.Item.BackColor = System.Drawing.Color.Ivory

End Sub

Private Sub DataGrid1_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.DataBinding


End Sub
End Class




各位老大 帮我看下 我表示出来的地方.
'myDeleteButton.Attributes.Add("onclick", "return confirm('您真的要删除第" + Str(Int(e.Item.ItemIndex.ToString) + 1) + " 行吗?');")
myDeleteButton.Attributes.Add("onclick", "return confirm('您真的要删除 " + e.Item.DataItem("users") + " 用户?');")

这两句. 如果我用上面的一句提示.他运行就很正常.

但是我如果用下面的一句提示,他会正常弹出提示.但是点确定或取消他会报错..
错误如下:



“/webnet”应用程序中的服务器错误。
--------------------------------------------------------------------------------

未设置对象变量或 With 块变量。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.NullReferenceException: 未设置对象变量或 With 块变量。

源错误:


行 74: myDeleteButton.Text = "删除"
行 75: 'myDeleteButton.Attributes.Add("onclick", "return confirm('您真的要删除第" + Str(Int(e.Item.ItemIndex.ToString) + 1) + " 行吗?');")
行 76: myDeleteButton.Attributes.Add("onclick", "return confirm('您真的要删除 " + e.Item.DataItem("users") + " 用户?');")
行 77:
行 78: End Select

源文件: E:\Myweb\Webnet\master.aspx.vb 行: 76

堆栈跟踪:


[NullReferenceException: 未设置对象变量或 With 块变量。]
Microsoft.VisualBasic.CompilerServices.LateBinding.LateIndexGet(Object o, Object[] args, String[] paramnames) +1242
WebApplication2.master.DataGrid_ItemCreated(Object Sender, DataGridItemEventArgs e) in E:\Myweb\Webnet\master.aspx.vb:76
System.Web.UI.WebControls.DataGrid.OnItemCreated(DataGridItemEventArgs e) +110
System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32 dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem, DataGridColumn[] columns, TableRowCollection rows, PagedDataSource pagedDataSource) +111
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean useDataSource) +1408
System.Web.UI.WebControls.BaseDataList.CreateChildControls() +61
System.Web.UI.Control.EnsureChildControls() +100
System.Web.UI.WebControls.BaseDataList.get_Controls() +12
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +292
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +414
System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +414
System.Web.UI.Page.LoadPageViewState() +306
System.Web.UI.Page.ProcessRequestMain() +423


--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573


搜索更多相关主题的帖子: System Imports Web 提示 Data 
2007-08-16 08:39
guyer
Rank: 2
等 级:新手上路
威 望:5
帖 子:451
专家分:0
注 册:2007-1-19
得分:0 

不知道这是为什么?..
难道他们之间有什么联系么?(我用红色表示出来的地方).
Sub DataGrid_ItemCreated(ByVal Sender As Object, ByVal e As DataGridItemEventArgs) Handles myDataGrid.ItemCreated
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem, ListItemType.EditItem
Dim myDeleteButton As Button
myDeleteButton = e.Item.FindControl("btnDelete")
myDeleteButton.Text = "删除"
'myDeleteButton.Attributes.Add("onclick", "return confirm('您真的要删除第" + Str(Int(e.Item.ItemIndex.ToString) + 1) + " 行吗?');")
myDeleteButton.Attributes.Add("onclick", "return confirm('您真的要删除 " + e.Item.DataItem("users") + " 用户?');")

End Select
End Sub
Private Sub myDataGrid_ItemCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles myDataGrid.ItemCommand
Response.Write("您要删除的是:<font color=red>" + e.Item.Cells(0).Text + "</font>")
'
'e.Item.BackColor = System.Drawing.Color.Ivory

End Sub


http://www./
2007-08-16 08:41



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-163046-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.230039 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved