台灣最大程式設計社群網站
線上人數
1188
 
會員總數:243663
討論主題:188255
歡迎您免費加入會員
討論區列表 >> ASP.NET >> gridview搜尋後分頁問題請教
[]  
[我要回覆]
1
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
gridview搜尋後分頁問題請教
價值 : 5 QP  點閱數:235 回應數:4

樓主

Chris
門外漢
0 1
19 3
發送站內信

請教各位大大

我做girdview搜尋頁面有分頁功能

搜尋後gridview顯示出搜尋的資料後,但是點選第二頁又會變成顯示搜尋前的顯示的資料

就是全部資料顯示出來

請問這該如何解決呢?





搜尋相關Tags的文章: [ gridview ] ,
本篇文章發表於2018-08-02 11:17
別忘捐VP感謝幫助你的人 新手會員瞧一瞧
1樓
回應

topcat
捐贈 VP 給 topcat 檢舉此回應
沒有看到你的搜尋如何做,很難跟您說問題出在哪
建議樓主把相關的程式碼顯示出來吧∼

^.^a
本篇文章回覆於2018-08-02 14:29
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
2樓
作者回應

Chris
檢舉此回應
[code]Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web

Partial Class sales
Inherits System.Web.UI.Page
Dim ConnStr As String = "Data Source=192.168.0.20;Initial Catalog=DB_TWNW;User ID=attn;pwd=attn@3100
"

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
'SetDb2ERP()
'MyDb.GetConnection()

Dim SrhSQLCMD As String
'Label1.Text = MyDb.GetConnection.ConnectionString

SrhSQLCMD = "SELECT C.NAME AS WH_NAME,A.PRD_NO,B.NAME,B.SPC,A.QTY FROM PRDT1 AS A INNER JOIN PRDT AS B ON A.PRD_NO = B.PRD_NO INNER JOIN MY_WH AS C ON C.WH = A.WH WHERE A.WH='BA1A1'"
'SetDb2ERP()
' MyDb.GetConnection()
SqlDataSource1.SelectCommand = SrhSQLCMD
SqlDataSource1.ConnectionString = ConnStr
GridView1.DataSourceID = "SqlDataSource1"
End Sub
Protected Sub GridView1_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
GridView1.DataBind()
End Sub
Protected Sub GridView1_Sorting(sender As Object, e As GridViewSortEventArgs) Handles GridView1.Sorting

End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Response.Write("<script> window.close();</script>")
End Sub
Protected Sub GridView1_PageIndexChanged(sender As Object, e As EventArgs) Handles GridView1.PageIndexChanged

End Sub
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Page.EnableViewState = True
' Dim Mykey As TextBox = CType(keyword, TextBox)
' Mykey.Attributes("onclick") = "javascript:clrtxbx(" & Mykey.ClientID & ")"
End Sub


Protected Sub srhBtn_Click(sender As Object, e As EventArgs) Handles srhBtn.Click
Dim SrhSqlCmd As String = ""
Dim Kfield As String = ""
Dim SrchOption As String = ""



SrhSqlCmd = "SELECT C.NAME AS WH_NAME,A.PRD_NO,B.NAME,B.SPC,A.QTY FROM PRDT1 AS A INNER JOIN PRDT AS B ON A.PRD_NO = B.PRD_NO INNER JOIN MY_WH AS C ON C.WH = A.WH WHERE A.WH='BA1A1' AND B.NAME like '%" + keyword.Text + "%'"

Label1.Text = SrhSqlCmd
SqlDataSource1.SelectCommand = SrhSqlCmd
SqlDataSource1.ConnectionString = ConnStr
GridView1.DataSourceID = "SqlDataSource1"
End Sub
End Class
本篇文章回覆於2018-08-02 14:46
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
3樓
作者回應

Chris
檢舉此回應

本篇文章回覆於2018-08-02 14:48
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
4樓
回應

topcat
捐贈 VP 給 topcat 檢舉此回應
我做girdview搜尋頁面有分頁功能

搜尋後gridview顯示出搜尋的資料後,但是點選第二頁又會變成顯示搜尋前的顯示的資料


先點出問題:
首先,先有的認知概念:WebForm任何動作都會PostBack回去,都會重新跑一遍
然後
您的搜尋是做在『srhBtn_Click』加上條件
按下後,的確因為您寫在裡面的查詢語法的變更,所以有篩選

按下第二頁,此時先跑過Page_Load事件,但『不會』再次觸發『srhBtn_Click』
因此不會有篩選

------
至於怎麼改,小喵我會這樣改
透過類別、Function、ObjectDataSource,去處理這一切
您參考以下這一篇#6小喵的回覆範例
http://www.blueshop.com.tw/board/FUM20041006161839LRJ/BRD20180718114036B5M.html

^_^
本篇文章回覆於2018-08-03 11:57
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
   
1

回覆
如要回應,請先登入.