|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Datagrid postback problem?!?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 Hi BRYAN
Could you show your code especially code in PageIndexChanged event? Elton Wang elton_w***@hotmail.com >-----Original Message----- default paging turned on and this is where I have a small >I have a datagrid that works perfectly well. I have problem. > button. When a user selects page 2 of the grid, for >My datagrid is created via the On_Click even of my search 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 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 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----- where I build the >Here is my code. I took out the section in the seach sub >SQL string for brevity reasons. ByVal e As > > > >Private Sub Page_Load(ByVal sender As System.Object, >System.EventArgs) Handles MyBase.Load System.Object, ByVal e As > >If Not Page.IsPostBack Then > >BindData() > >End If > >End Sub > > > >Private Sub btnSearch_Click(ByVal sender As >System.EventArgs) Handles btnSearch.Click ("server=ntsrvgvs37;database=AgreementProfile;uid=agreement> >Dim temp As String > >'Create SQL Query string > > > >Dim strSQL As String = "SELECT * FROM uvwHeader" & temp > >Dim mySQL As New >SqlConnection 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 > > >. > 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". -- Show quoteHide quoteBRYAN 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 >> >> >>. >> What I said is
SearchGrid.CurrentPageIndex = E.NewPageIndex SearchGrid.DataSource = myDataSet SearchGrid.DataBind() Show quoteHide quote >-----Original Message----- ("server=ntsrvgvs37;database=AgreementProfile;uid=agreement>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 >> 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 >>> >>> >>>. >>> > > >. > 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? -- Show quoteHide quoteBRYAN 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 >>> 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 >>>> >>>> >>>>. >>>> >> >> >>. >> 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----- explained. Is there >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 Show quoteHide quote >a way to pass the myDataSet to the SearchGrid_PageChanger ("server=ntsrvgvs37;database=AgreementProfile;uid=agreementSub? > >-- > >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 >>>> >> 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 >>>>> >>>>> >>>>>. >>>>> >>> >>> >>>. >>> > > >. > bind the grid again in the PageIndexChanged event.
>-----Original Message----- default paging turned on and this is where I have a small >I have a datagrid that works perfectly well. I have problem. > button. When a user selects page 2 of the grid, for >My datagrid is created via the On_Click even of my search 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
Searched Datagrid with Paging?
Using Server.Transfer with HyperLinkColumn in a datagrid Questions concerning detailsview or datagrid ASP.NET 2.0 Export to PDF How can I export a Dataview to Excel customising PagerStyle Showing x to y of z records Fonction de recherche dans un datagrid dynamically create datagrid and set its datasource in VB.NET search function on different page selected |
|||||||||||||||||||||||