Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

使名扬老师请进,有一些问题问问你哦

0 views
Skip to first unread message

Mikeda

unread,
May 18, 2005, 9:04:06 AM5/18/05
to
我在用DataGrid做分页的时候出现了以下的问题!
我希望用dropdownlist的AutoPostBack然后实现用户信息和图书信息的切换管理
切换的过程中,DataGrid实现动态切换
在某一个表中分页都好使,但是当这种情况时候出问题
我的用户表假设有三页,图书表有两页
当我看用户表第三页的时候,再点下拉菜单切换到图书表的时候
他仍然是第三页,因为图书表共两页,出错!

附程序:(希望使名扬老师多多提意见,谢谢)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
btnFirst.Text = "最首页"
btnPrev.Text = "前一页"
btnNext.Text = "下一页"
btnLast.Text = "最后页"
'OpenDatabase()
conn.Close()
End Sub
Sub MyDataGrid_Page(ByVal sender As Object, ByVal e As
DataGridPageChangedEventArgs)
Dim startIndex As Integer
startIndex = MyDataGrid.CurrentPageIndex * MyDataGrid.PageSize
MyDataGrid.CurrentPageIndex = e.NewPageIndex
BindGrid()
ShowStats()
End Sub
Sub BindGrid()
Dim oradb As String = "Provider=MSDAORA;Data Source=orcl;User
Id=scott;Password=tiger;"
Dim Conn As OleDbConnection = New OleDbConnection(oradb)
Dim myConnection As OleDbConnection = Conn
Conn.Open()
'myConnection.Open()
Dim ds As New DataSet
Dim strSQL As String
Dim adapter As OleDbDataAdapter
If Session("n") = 1 Then
strSQL = "select * from mikedauser"
adapter = (New OleDbDataAdapter(strSQL, Conn))
Session.Clear()
ElseIf Session("n") = 0 Then
strSQL = "select * from mikedabook"
adapter = (New OleDbDataAdapter(strSQL, Conn))
Session.Clear()
End If
'将数据填如DataSet对象中
adapter.Fill(ds, "dataset1")
MyDataGrid.DataSource = ds.Tables("dataset1").DefaultView
MyDataGrid.DataBind()
ShowStats()
End Sub
Sub PagerButtonClick(ByVal sender As Object, ByVal e As EventArgs)
'used by external paging UI
Dim arg As String = sender.CommandArgument
Select Case arg
Case "next"
If (MyDataGrid.CurrentPageIndex < (MyDataGrid.PageCount -
1)) Then
MyDataGrid.CurrentPageIndex += 1
End If
Case "prev"
If (MyDataGrid.CurrentPageIndex > 0) Then
MyDataGrid.CurrentPageIndex -= 1
End If
Case "last"
MyDataGrid.CurrentPageIndex = (MyDataGrid.PageCount - 1)
Case Else
'page number
MyDataGrid.CurrentPageIndex = System.Convert.ToInt32(arg)
End Select
BindGrid()
ShowStats()
End Sub
Sub ShowStats()
lblCurrentIndex.Text = "第 " + (MyDataGrid.CurrentPageIndex +
1).ToString() + " 页"
lblPageCount.Text = "总共 " + MyDataGrid.PageCount.ToString() + " 页"
End Sub
Public conn As New OleDbConnection
Public n = 1
Public Sub OpenDatabase()
Dim oradb As String = "Provider=MSDAORA;Data Source=orcl;User
Id=scott;Password=tiger;"
Dim Conn As OleDbConnection = New OleDbConnection(oradb)
Conn.Open()
End Sub

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged
If DropDownList1.SelectedValue = "userinfo" Then
Session("n") = 1
DropDownList2.Items.Clear()
DropDownList2.Items.Add("用户名")
DropDownList2.Items.Add("真实姓名")
DropDownList2.Items.Add("性别")
Dim oradb As String = "Provider=MSDAORA;Data Source=orcl;User
Id=scott;Password=tiger;" ' VB.NET
Dim strSQL = "SELECT * FROM mikedauser"
Dim Conn As OleDbConnection = New OleDbConnection(oradb)
Dim bookds As New DataSet
Dim bookadpt As OleDbDataAdapter = New OleDbDataAdapter(strSQL,
Conn)
bookadpt.Fill(bookds, "DataSet2")
MyDataGrid.DataSource = bookds.Tables("Dataset2").DefaultView
MyDataGrid.DataBind()
Conn.Close()
ElseIf DropDownList1.SelectedValue = "bookinfo" Then
Session("n") = 0
DropDownList2.Items.Clear()
DropDownList2.Items.Add("图书序号")
DropDownList2.Items.Add("图书书号")
DropDownList2.Items.Add("图书书名")
DropDownList2.Items.Add("图书类别")
DropDownList2.Items.Add("图书作者")
DropDownList2.Items.Add("图书版本")
DropDownList2.Items.Add("书出版社")
DropDownList2.Items.Add("图书数量")
DropDownList2.Items.Add("图书价位")
DropDownList2.Items.Add("库存时间")
Dim oradb As String = "Provider=MSDAORA;Data Source=orcl;User
Id=scott;Password=tiger;" ' VB.NET
Dim strSQL = "SELECT * FROM mikedabook"
Dim Conn As OleDbConnection = New OleDbConnection(oradb)
Dim myds As New DataSet
Dim myadpt As OleDbDataAdapter = New OleDbDataAdapter(strSQL,
Conn)
myadpt.Fill(myds, "DataSet1")
MyDataGrid.DataSource = myds.Tables("Dataset1").DefaultView
MyDataGrid.DataBind()
Conn.Close()
End If
End Sub


使名扬

unread,
May 18, 2005, 7:39:49 PM5/18/05
to
1.在DropDownList1_SelectedIndexChanged
你应该把MyDataGrid.CurrentPageIndex清0。

2.你的这个分页效率上很有问题,这种select * from mikedauser SQL用上去,这个系统用个几个月,肯定慢的要死。

3.我的BLOG上不是有oracle的专用分页控件么。http://www.cnblogs.com/tongzhenhua/archive/2005/02/10/103685.html
基本上这个控件还是很稳定的,只要你的SQL别写错。


--
被最牛的软件公司牵着鼻子走是我们这些牛的荣幸
移动开发,美丽新世界。今天你还在做传统开发么?
╭╮︵︵╭╮.╔═════════╗.
〔 ∩∩ 〕.‖╭使╮╭名╮╭扬╮‖.
〔ミ e ミ〕.‖.╲╱..╲╱..╲╱.‖.
(︵灬 灬︵〕╚═════════╝.
真实姓名:童振华
精华区 ASP.net管管
另请不要直接发邮件给我,我只有2M的hotmail耶,昨天一天收了34份信,删删很麻烦的。NG我天天在看的
"Mikeda" <miked...@163.com> 写入消息
news:e2kvZo6W...@TK2MSFTNGP09.phx.gbl...

0 new messages