Datagrid postback problem?!?

B

Bryan Fickle

I have a datagrid that works perfectly well. I have default paging turned on and this is where I have a small problem.

My datagrid is created via the On_Click even of my search button. When a user selects page 2 of the grid, for example, the grid disappears. If you press the search button again, page 2 of the grid will appear.....same for any page....click on page 3, grid disappears, click search, page 3 of grid appears. The data is always correct, but I just can't solve this issue.

Any help would be appreciated.
 
E

Elton Wang

Hi BRYAN

Could you show your code especially code in
PageIndexChanged event?

Elton Wang
(e-mail address removed)

-----Original Message-----
I have a datagrid that works perfectly well. I have
default paging turned on and this is where I have a small
problem.
My datagrid is created via the On_Click even of my search
button. When a user selects page 2 of the grid, for
example, the grid disappears. If you press the search
button again, page 2 of the grid will appear.....same for
any page....click on page 3, grid disappears, click
search, page 3 of grid appears. The data is always
correct, but I just can't solve this issue.
 
G

Guest

bind the grid again in the PageIndexChanged event.
-----Original Message-----
I have a datagrid that works perfectly well. I have
default paging turned on and this is where I have a small
problem.
My datagrid is created via the On_Click even of my search
button. When a user selects page 2 of the grid, for
example, the grid disappears. If you press the search
button again, page 2 of the grid will appear.....same for
any page....click on page 3, grid disappears, click
search, page 3 of grid appears. The data is always
correct, but I just can't solve this issue.
 
B

Bryan Fickle

Here is my code. I took out the section in the seach sub where I build the
SQL string for brevity reasons.



Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not Page.IsPostBack Then

BindData()

End If

End Sub



Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSearch.Click

Dim temp As String

'Create SQL Query string



Dim strSQL As String = "SELECT * FROM uvwHeader" & temp

Dim mySQL As New
SqlConnection("server=ntsrvgvs37;database=AgreementProfile;uid=agreementprofileweb;pwd=roysmess")

mySQL.Open()

Dim myCommand As New SqlCommand(strSQL, mySQL)

Dim myAdapter As New SqlDataAdapter(myCommand)

Dim myDataSet As New DataSet

myAdapter.Fill(myDataSet)

'Bind DataGrid with search results

SearchGrid.DataSource = myDataSet

SearchGrid.DataBind()

'Close connection

mySQL.Close()

End Sub



Sub SearchGrid_PageChanger(ByVal Source As Object, _

ByVal E As DataGridPageChangedEventArgs)

'Set the CurrentPageIndex

SearchGrid.CurrentPageIndex = E.NewPageIndex

SearchGrid.DataBind()

End Sub
 
E

Elton Wang

You should rebind data source in SearchGrid_PageChanger
like

SearchGrid.CurrentPageIndex = E.NewPageIndex
SearchGrid.DataSource =
DataSet_You_Got_in_btnSearch_Click
SearchGrid.DataBind()

HTH

Elton Wang
 
B

Bryan Fickle

Hi Elton,

So you are saying it should look like this?

SearchGrid.DataSource =SearchGrid.DataBind()

It does not like that. I'm guessing it should look like this then...

SearchGrid.DataSource = myDataSet
SearchGrid.DataBind()

but my page change sub can't see "myDataSet".
 
E

Elton Wang

What I said is

SearchGrid.CurrentPageIndex = E.NewPageIndex
SearchGrid.DataSource = myDataSet
SearchGrid.DataBind()
 
B

Bryan Fickle

I understand that much, but I guess my question is, Sub
SearchGrid_PageChanger can't see myDataSet.

It says it is undefined if I type it in exaclty how you explained. Is there
a way to pass the myDataSet to the SearchGrid_PageChanger Sub?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top