I have a GridView that shows particular data and records when I click Generate button.
My problem is that when I click for the next page of the GridView list the Gridview will be lost (blank), I don't think the data will be lost too, I guess the GirdView just doesn't show it.
Can you please help me with this problem. I'm not the one who first create this website and I tried all the things that I know for this problem, I also searched for a solutions in the internet with no luck. So I hope someone can tell me why is the GridView not showing after clicking the next page.
Here's the code for the Page_Load
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
userid = IIf(SessionHandler.UserID = "", User.Identity.Name.ToUpper, SessionHandler.UserID)
V3Substance.Attributes.Add("onfocus", "javascript:if (this.value=='Substance Cas Number') { this.value = ''; }")
V3Substance.Attributes.Add("onblur", "javascript:if (this.value=='') { this.value = 'Substance Cas Number'; }")
If Not Page.IsPostBack Then
V1Division.DataSource = GetDivision()
V1Division.DataBind()
V1BR.Items.Clear()
V1BR.DataSource = GetBusinessRule(V1Division.Text)
V1BR.DataBind()
MultiView1.ActiveViewIndex = 0
Panel1.DefaultButton = "V1Generate"
End If
End Sub
Here's the code for GridView1_PageIndexChanging
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
Dim dt As DataTable = TryCast(GridView1.DataSource, DataTable)
GridView1.DataSource = SortTable(dt)
GridView1.PageIndex = e.NewPageIndex
GridView1.DataBind()
End Sub
Here's the code for BindGridView
Private Sub BindGridview(ByVal query As String, ByVal countquery As String)
ViewState.Add("Query", query)
ViewState.Add("CountQuery", countquery)
Dim count As Integer = 0
If Description.Text = "1" Then
ValidateFamily(query)
Else
DataSource = dbHelper.GetRecordDT(query)
End If
count = DataSource.Rows.Count
GridView1.DataSource = DataSource
GridView1.Visible = True
GridView1.DataBind()
ExportToExcel.Visible = IIf(count < 1, False, True)
Panel1.Visible = IIf(count < 1, False, True)
SetTotalResult(count)
End Sub
What I have tried:
First I tried putting
GridView1.Visible = True
in GridView1_PageIndexChanging and the result is the GridView with the data will show and when I click the next page it shows No Record Found.
I also tried putting this code in Page_Load
If ViewState.Item("Query") <> Nothing Then
BindGridview(ViewState.Item("Query"), ViewState.Item("CountQuery"))
End If
The result is when I click the Generate button first the data will show in the GridView and also when I click the next page but when I choose another item in the DropDownList and click Generate button again the data will be lost again (blank).