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