Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I have searched the forums but, I can't seem to find anything that speaks to this:

 

I have a GridView in my web app that retrieves data via a SQLDataSource. When the page opens, it automatically displays all data found in a particular table. I have three problems that I suspect are all related:

 

Problem #1:

I have a vb text box and button that allows the user to enter a phrase and click search. So far, that part is working pretty good. Below is the code that is executed when they click search:

 

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

  Me.sqlArchive.SelectCommand = "SELECT * FROM ARCHIVEHOLDINGS WHERE CONTAINS(*,'" & Me.txSearch.Text & "') ORDER BY TITLE ASC"

End Sub

 

I get the desired effect where the grid's data changes to include only what matches the search text. However, when someone clicks on the header to sort the results, it goes back to the original query which is as follows:

 

Me.sqlArchive.SelectCommand="SELECT * FORM ARCHIVEHOLDINGS ORDER BY TITLE ASC"

 

Problem #2:

If the search results return more than one page, clicking on the page you want to go to also reverts back to the original query.

 

Problem #3:

I have a button that allows the user to reset grid to the original query, or clear the query results. The code is as follows:

Protected Sub btReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btReset.Click
       Dim sSortDir As String

       If Me.gvArchives.SortExpression <> "" Then
           If gvArchives.SortDirection = SortDirection.Ascending Then
               sSortDir = "ASC"
           Else
               sSortDir = "DESC"
           End If
           Me.sqlArchive.SelectCommand = "SELECT * FROM ARCHIVEHOLDINGS ORDER BY " & Me.gvArchives.SortExpression & " " & sSortDir
           Me.gvArchives.DataSourceID = "sqlArchive"
           Me.gvArchives.DataBind()
       Else
           Me.sqlArchive.SelectCommand = "SELECT * FROM ARCHIVEHOLDINGS ORDER BY Title ASC"
           Me.gvArchives.DataSourceID = "sqlArchive"
           Me.gvArchives.DataBind()
       End If

       Me.txSearch.Text = ""

   End Sub

The above code sort of works. It causes the grid to return to its original state but, the paging on the bottom only matches the previous search query.

 

What else do I need to post to give someone a good idea of what I am trying to do?

 

Any help would be appreciated. Thank you.

Edited by shanekahkola
Posted

In relation to problem 1, the grid is doing a post back which effectively reloads the data. Try placing your call to the database inside an if not ispostback statement.

 

Mike55.

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

Posted
In relation to problem 1, the grid is doing a post back which effectively reloads the data. Try placing your call to the database inside an if not ispostback statement.

 

Mike55.

I did like you said and put a conditional clause in for IsPostBack. I just had a message box pop-up for true and the query for false.

 

For my own sanity, what are the drawbakcs of turning-off postback? If you prefer to post a couple of links that will send me in the right direction, that's just as good as you answering the question.

 

Thank you for taking the time.

Posted (edited)

For background information on this particular post, please read my initial post and Mike55's response?

 

I have done quite a bit of reading on ViewState and PostBack. I am having a difficult time processing everything I have read. I have decided to simplify a few questions and see if I can get some answers.

 

Question 1:

I have a DataGrid populated by SQLDataSource. PostBack is enabled in order to allow me to use the Grid's built-in sorting capabilities. Which is better? Remove the postback feature and script my own sorting or, leave the postback feature and use some other method for altering the data with searched criteria?

 

Question 2:

If I should leave postback enabled, what is the method I need to use to change the datagrid results so that the user can sort the new results instead of having the datagrid revert back to the original query?

 

Quesiton 3:

Am I just stupid and in need of giving up any attempts to program?

Edited by shanekahkola

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...