Home All Groups Group Topic Archive Search About
Author
16 Mar 2005 4:34 PM
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.

--

BRYAN FICKLE
bry***@email.uophx.edu

Author
16 Mar 2005 8:24 PM
Elton Wang
Hi BRYAN

Could you show your code especially code in
PageIndexChanged event?

Elton Wang
elton_w***@hotmail.com


>-----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. 
Show quoteHide quote
>
>Any help would be appreciated.
>
>--
>
>BRYAN FICKLE
>bry***@email.uophx.edu
Author
16 Mar 2005 8:37 PM
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


--

BRYAN FICKLE
bry***@email.uophx.edu
Author
16 Mar 2005 11:03 PM
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


>-----Original Message-----

>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=agreement
profileweb;pwd=roysmess")
Show quoteHide quote
>
>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
>
>
>--
>
>BRYAN FICKLE
>bry***@email.uophx.edu
>
>
>.
>
Author
17 Mar 2005 12:50 PM
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".
--

BRYAN FICKLE
bry***@email.uophx.edu

Show quoteHide quote
"Elton Wang" <anonym***@discussions.microsoft.com> wrote in message
news:08d301c52a7c$569fc630$a501280a@phx.gbl...
> 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
>
>
>>-----Original Message-----
>
>>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=agreement
> profileweb;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
>>
>>
>>--
>>
>>BRYAN FICKLE
>>bry***@email.uophx.edu
>>
>>
>>.
>>
Author
17 Mar 2005 2:56 PM
Elton Wang
What I said is

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


Show quoteHide quote
>-----Original Message-----
>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".
>--
>
>BRYAN FICKLE
>bry***@email.uophx.edu
>
>"Elton Wang" <anonym***@discussions.microsoft.com> wrote
in message
>news:08d301c52a7c$569fc630$a501280a@phx.gbl...
>> 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
>>
>>
>>>-----Original Message-----
>>
>>>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=agreement
Show quoteHide quote
>> profileweb;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
>>>
>>>
>>>--
>>>
>>>BRYAN FICKLE
>>>bry***@email.uophx.edu
>>>
>>>
>>>.
>>>
>
>
>.
>
Author
17 Mar 2005 3:44 PM
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?

--

BRYAN FICKLE
bry***@email.uophx.edu

Show quoteHide quote
"Elton Wang" <anonym***@discussions.microsoft.com> wrote in message
news:0d0301c52b01$78a07330$a401280a@phx.gbl...
> What I said is
>
> SearchGrid.CurrentPageIndex = E.NewPageIndex
> SearchGrid.DataSource = myDataSet
> SearchGrid.DataBind()
>
>
>>-----Original Message-----
>>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".
>>--
>>
>>BRYAN FICKLE
>>bry***@email.uophx.edu
>>
>>"Elton Wang" <anonym***@discussions.microsoft.com> wrote
> in message
>>news:08d301c52a7c$569fc630$a501280a@phx.gbl...
>>> 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
>>>
>>>
>>>>-----Original Message-----
>>>
>>>>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=agreement
>>> profileweb;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
>>>>
>>>>
>>>>--
>>>>
>>>>BRYAN FICKLE
>>>>bry***@email.uophx.edu
>>>>
>>>>
>>>>.
>>>>
>>
>>
>>.
>>
Author
17 Mar 2005 5:09 PM
Elton Wang
There are two ways to do it.

1. use Session to save the datasource.
you can take look from following url
http://www.asp.net/Forums/ShowPost.aspx?
tabindex=1&PostID=857462

2. each time re-quire the database to get the datasource
myDataSet.

HTH

Elton Wang


>-----Original Message-----
>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
Show quoteHide quote
>a way to pass the myDataSet to the SearchGrid_PageChanger
Sub?
>
>--
>
>BRYAN FICKLE
>bry***@email.uophx.edu
>
>"Elton Wang" <anonym***@discussions.microsoft.com> wrote
in message
>news:0d0301c52b01$78a07330$a401280a@phx.gbl...
>> What I said is
>>
>> SearchGrid.CurrentPageIndex = E.NewPageIndex
>> SearchGrid.DataSource = myDataSet
>> SearchGrid.DataBind()
>>
>>
>>>-----Original Message-----
>>>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".
>>>--
>>>
>>>BRYAN FICKLE
>>>bry***@email.uophx.edu
>>>
>>>"Elton Wang" <anonym***@discussions.microsoft.com> wrote
>> in message
>>>news:08d301c52a7c$569fc630$a501280a@phx.gbl...
>>>> 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
>>>>
>>>>
>>>>>-----Original Message-----
>>>>
>>>>>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=agreement
Show quoteHide quote
>>>> profileweb;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
>>>>>
>>>>>
>>>>>--
>>>>>
>>>>>BRYAN FICKLE
>>>>>bry***@email.uophx.edu
>>>>>
>>>>>
>>>>>.
>>>>>
>>>
>>>
>>>.
>>>
>
>
>.
>
Author
16 Mar 2005 8:37 PM
anonymous
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. 
Show quoteHide quote
>
>Any help would be appreciated.
>
>--
>
>BRYAN FICKLE
>bry***@email.uophx.edu