能这样试试吗?
1、引入明明空间,将manager.vb,引用到当前的页面中,声明其实例,在引用其中的datagrid控件。
2、声明主窗体的实例,引用其中的控件。
不管咋样,我觉得你第一要做的都是获得主窗体的引用。
1、引入明明空间,将manager.vb,引用到当前的页面中,声明其实例,在引用其中的datagrid控件。
2、声明主窗体的实例,引用其中的控件。
不管咋样,我觉得你第一要做的都是获得主窗体的引用。
解决方案 »
- 网站和软件的区别
- 怎么样用JS来触发页面内所有的Validate, 就好象后台的..Page.Validate.
- asp.net replace如何只执行一次?
- 求单独购物车功能项目!!
- ftp操作
- SQL语句的问题
- 大家一般怎样实现网站浏览人数统计?
- 如何控制Gridview编辑时候的列的长度
- |M| 如何记录对SQL数据库的每一次操作 网站安全方面的 大家说说要怎么来做 讨论
- 请大侠指点,看似简单的问题:不用href,如何让<A onclick=...>DoIt </a>看起来象超链接(即鼠标变手)?
- 简单问题
- Selected collating sequence not supported by the operating system.我该怎么办?
manager.vb:
Imports System
Imports System.IO
Imports System.ComponentModel
Imports System.Data
Imports System.Data.OleDb
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Configuration
Imports Microsoft.VisualBasicPublic Class manager
Inherits System.Web.UI.Page
public mylist 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
private sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Mybase.load
Dim conn as OleDbConnection
Dim cmd as OleDbDataAdapter
Dim ds as New DataSet
if (Session("name") <> ConfigurationSettings.AppSettings("站长")) then
Response.Redirect("log.aspx")
end if
conn =New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& Server.MapPath("new.mdb"))
cmd = New OleDbDataAdapter("SELECT * from aa WHERE typeid=1 order by shijian desc",conn)
cmd.Fill(ds,"aa")
mylist.DataSource=ds.Tables("aa").DefaultView
mylist.DataBind()
end sub
public sub MyDataGrid_Delete(ByVal sender As System.Object, ByVal e As DataGridCommandEventArgs)
Dim conn as OleDbConnection
Dim delcmd as New OleDbCommand
Dim ds as New DataSet
Dim temp as integer conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="& Server.MapPath("new.mdb"))
delcmd.CommandText = "DELETE from aa where id =****"
delcmd.connection = conn
delcmd.Connection.Open
delcmd.ExecuteNonQuery()
delcmd.Connection.Close
Response.Redirect("manager.aspx")
end subend class
---------------------------------
manager.aspx:
<ASP:DataGrid id="MyList"
AllowPaging="True"
PageSize="20"
PagerStyle-Visible="false"
runat="server"
Width="500"
GridLines="None"
ShowFooter="false"
CellPadding="2"
CellSpacing="1"
Font-Name="宋体"
Font-Size="8pt"
EnableViewState="false"
AutoGenerateColumns="false"
DataKeyField="id"
OnDeleteCommand="MyDataGrid_Delete"
> <Columns>
<asp:BoundColumn ItemStyle-Width="150px" HeaderText="" DataField="shijian" />
<asp:BoundColumn ItemStyle-Width="400px" HeaderText="" DataField="biaoti" />
<asp:ButtonColumn ItemStyle-Width="100px" Text="删除" CommandName="Delete"/>
</Columns> </asp:DataGrid>
问题:
我想在manager.vb中取得manager.aspx中的datagrid的DataKeyField的值可以吗?(以下的****部位)
("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="& Server.MapPath("new.mdb"))
delcmd.CommandText = "DELETE from aa where id =****"
delcmd.connection = conn
delcmd.Connection.Open
delcmd.ExecuteNonQuery()
delcmd.Connection.Close
Response.Redirect("manager.aspx")
1、在定义DG的列集合属性时要加入datakeyfield(即主键)列;
2、MANAGER.VB的代码:
'执行删除
Public Sub dg_Item(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
If e.CommandName = "Delete" Then
Dim del As Integer
Dim dc As SqlConnection
Dim cm As SqlCommand
Dim da As SqlDataAdapter
Dim ds As DataSet
'获得任一行id值 /////////////
del = e.Item.Cells(0).Text
'///////////////////////////////
dc = New SqlConnection(classconn.strconn)
dc.Open() cm = New SqlCommand("delete from e_xmry where id=" & del, dc)
cm.ExecuteNonQuery()
'重新绑定表格
da = New SqlDataAdapter("select * from ....", dc)
ds = New DataSet()
da.Fill(ds, "e_xmry")
dg.DataSource = ds
If dg.Items.Count = 1 Then
If dg.PageCount = 2 Then
dg.CurrentPageIndex = 0
ElseIf dg.PageCount > 2 Then
dg.CurrentPageIndex = dg.CurrentPageIndex - 1
End If
End If
xh1 = 5 * dg.CurrentPageIndex
dg.DataBind()
End If
End Sub
3、若要实现批删除,建议添加模板列(checkbox),选中的将其id值记入数组,单独在button的click事件下实现批删除:
delcmd.CommandText = "DELETE from aa where id in('数组')"