再发一个初级问题,请各位帮忙!
再发一个初级问题,请各位帮忙,问题解决明天就结贴!
下面是我做的一个分页和排序结合的程序,程序进入后显示20条记录!
点分页每次显示20条,点排序也是每次排序前20记录。
但每次我先点完排序再点分页的时候就会显示40条记录,这时我再分页还是20显示条记录!
我实在搞不清到底是为什么?
我连接也关闭了,dataset也clear了datasource也每次使用前设为空了,怎么就会把排序的记录和分页的记录数加到一起了呢(20+20=40条了)?
代码如下:
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
Dim tablename As String = "rs_grda"
Dim fieldlist As String = "sn,bmbm AS 部门编码,grbm AS 个人编码,xm AS 姓名,sex AS 性别,birthday AS 出生日期,politic AS 政治面貌,zw AS 职务,zc AS 职称,tocurrent AS 入本企业时间,tojtcurrent AS 入集团时间,if_ylbx AS 是否交纳养老保险,dh AS 电话,idencode AS 身份证,byxy AS 毕业学校,bysj AS 毕业时间,if_gd AS 是否股东,introduce_bmbm AS 工资发放部门,flag AS 员工状态,wh AS 文化程度,marry AS 婚否,worker AS 工种,hkxz AS 户口性质,sh_flag AS 审核标志,founder_flag AS 是否是创业老员工"
If hi.Value = "" Then
hi.Value = "xm asc"
End If
Dim orderfield As String = hi.Value
Dim keyfield As String = "sn"
Dim pageindex As Integer = 1
Dim pagesize As Integer = 20
Dim strwhere As String = "xm like '%" & TextBox2.Text.Trim & "%'"
Dim ordertype As Boolean = False
Dim sqlstr As String
sqlstr = sqlcount(tablename, fieldlist, orderfield, keyfield, pageindex, pagesize, strwhere, ordertype)
Label2.Text = sqlstr
'If Not IsPostBack Then
Dim queryStringa As String = sqlstr
Dim connectionString As String = "server=192.168.7.10;uid=dynetuser;pwd=nmamtf;database=dynet"
Dim connection As New SqlConnection(connectionString)
Dim adaptera As New SqlDataAdapter(queryStringa, connection)
Dim dsssa As DataSet = New DataSet()
adaptera.Fill(dsssa, "ddd")
If dsssa.Tables.Count > 0 Then
Label1.Text = dsssa.Tables.Count
GridView1.DataSource = Nothing
GridView1.DataBind()
GridView1.DataSource = dsssa
GridView1.DataMember = "ddd"
GridView1.DataBind()
dsssa.Clear()
connection.Close()
Else
Message.Text = "Unable to connect to the database."
End If
End Sub
————————————————————————————————————
Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
Dim sortstr As String = e.SortExpression
If ViewState("SortDirction") = "" Then
ViewState("SortDirction") = "desc"
Else
If ViewState("SortDirction").ToString = "asc" Then
ViewState("SortDirction") = "desc"
Else
ViewState("SortDirction") = "asc"
End If
End If
Dim orderfield As String = sortstr & " " & ViewState("SortDirction")
hi.Value = orderfield
Dim queryString As String = "select top 20 sn,bmbm AS 部门编码,grbm AS 个人编码,xm AS 姓名,sex AS 性别,birthday AS 出生日期,politic AS 政治面貌,zw AS 职务,zc AS 职称,tocurrent AS 入本企业时间,tojtcurrent AS 入集团时间,if_ylbx AS 是否交纳养老保险,dh AS 电话,idencode AS 身份证,byxy AS 毕业学校,bysj AS 毕业时间,if_gd AS 是否股东,introduce_bmbm AS 工资发放部门,flag AS 员工状态,wh AS 文化程度,marry AS 婚否,worker AS 工种,hkxz AS 户口性质,sh_flag AS 审核标志,founder_flag AS 是否是创业老员工 from rs_grda where xm like '%" & TextBox2.Text.Trim & "%' order by " & orderfield
Dim connectionString As String = "server=192.168.7.10;uid=dynetuser;pwd=nmamtf;database=dynet"
Dim connection As New SqlConnection(connectionString)
Dim adapter As New SqlDataAdapter(queryString, connection)
Dim dsss As DataSet = New DataSet()
adapter.Fill(dsss, "ddd")
If dsss.Tables.Count > 0 Then
Label1.Text = dsss.Tables.Count
GridView1.DataSource = Nothing
GridView1.DataSource = dsss
GridView1.DataMember = "ddd"
GridView1.DataBind()
dsss.Clear()
connection.Close()
Else
Message.Text = "Unable to connect to the database."
End If
'Dim conn As New SqlConnection("server=192.168.7.10;uid=dynetuser;pwd=nmamtf;database=dynet")
'Dim sql As String = ("drop table new table")
End Sub
————————————————————————————