Displaying randomised search results in GridView

I have an MS-SQL Stored Procedure that returns search results in a random order each time it is executed. These results are displayed in a GridView through an SqlDataSource control but I've discovered a problem with results that span across more than one page on the GridView. If a link in the pager is selected, sometimes a result appears that was also on another page.

Of course, what's happening is that each time a link in the pager is selected, it executes the stored procedure and gets another set of random search results which leads to some results appearing on different pages.

So what I need to do is execute the stored procedure when the gridview is first initialised and keep the same results active each time the gridview pager links are selected. Anyone know how to do this? Would I have to use something like a DataSet instead of the SqlDataSource?

0
Tickled_Pink
2/1/2007 4:43:57 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

2 Replies
548 Views

Similar Articles

[PageSpeed] 57
Get it on Google Play
Get it on Apple App Store

Hi   Tickled_Pink,

Yes.

You can retrieve data into dataset and bind it to GridView .

Or how about adding ORDER BY clause to sql statement to avoid random result.

Here is sample code on bind dataset to GridView:

// you can use this line 

string connectionString = myDataSource.ConnectionString; 

// you can also use this line since by using the SqlDataSource it makes an entry in the
// web.config file if that is what choose to do
//string connectionString = (string)ConfigurationSettings.AppSettings["ConnectionString"];
// if you are using Enterprise Library you can also use
//string connectionString = (string)ConfigurationSettings.ConnectionStrings["ConnectionString"]; 

SqlConnection myConnection = new SqlConnection(connectionString);

SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM Categories", myConnection);

DataSet ds = new DataSet();

ad.Fill(ds, "Categories");

myGridView.DataSource = ds;

myGridView.DataBind(); 

 

Remember if you have large data using dataset will result in poor performance.

Hope this helps.


NOTE:If you find my response contains a reference to a third party World Wide Web site, I am providing this information as a convenience to you.Microsoft does not control these sites and has not tested any software or information found on these sites; therefore,Microsoft cannot make any representations regarding the quality,safety, or suitability of any software or information found there.
__________________________________________________

Sincerely,
Young Fang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
0
Young
2/5/2007 5:46:50 AM
Thanks. I'll give the datasets a try. Random results are necessary to give advertisers 'equal' prominance on the site.
0
Tickled_Pink
2/5/2007 11:58:42 AM
Reply:

Similar Artilces:

search engine and displaying search results with gridview
 Hi all,I am a newbie with ASP.NET.I have a gridview that display data from the database.I want to implement a search engine. When the user enters a keyword in the textbox then click on the search button the result will be displayedto the gridview. How do I do this? How do I implement a search engine so that when the user enters a keyword on the textbox and hit the search button the data will then be displayed in the gridview? Here's is my code. The texbox and search button are highlighted in bold case: <%@ Page Language="C#" AutoEventWireup="true"&n...

Display Multiple Datasets in a Single GridView or Use a Timer Control to Display Multple Results
I am trying to get the gridview to display the results of multiple dataset that containg SQL Queries. I have a combobox that allows the user to select a Query to run and then it returns the results to the datagrid, however I can not get it to display multiple results in the same gridview. The following works now to display one along with else if but I need to display all selected at the sametime. I have been advise that this may not be possible, and if it's not can someone direct me on using a Timer Control to display multiple DataSet results in various intervals on the same DataGrid. ...

Display Search Results in GridView
How would I go about displaying search results in a gridview.  My confusion is centered around the fact that when the page loads there is no data to display until a search is performed.  I have two thoughts on this. Put a literal in as a place holder and then in the code behind for the search button create the datasource and write out all the asp code for the datagrid to the literal.  My other thought is to have the gridview in the default.aspx but marked as not visible.  Then when I perform the search set the datasourceid property and mark it visible. I am not sure if th...

How to Display Search Result Into a Gridview
Hi Folks! I'm stuck with my VB 2005 web project in writing the code for a button_click event that will display the search result in a gridview from the database. I have a textbox where the user types in the keyword. I have done up a query in the objectDataSource which is: SELECT * From tblBookingsWHERE Event LIKE '%' + @Event + '%' Can anyone please point me to the right direction? Much appreciate your advices. Cheers! Resty  see this example  <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="tru...

Displaying "Sorry there were no results for your search" for a search that yields no results
Hello, I've got an SQL datasource and a GridView control on a page called textsearch.aspx (in a VS web application). The text that the user is searching for is passed in as a querystring - e.g. if the user searches for "clematis" he's navigated to textsearch.aspx?Search=clematis. This all works fine as long as there is something that's called "clematis" (or whatevers being search for) in my database. However, if there are no matches in my database nothing is displayed (except for what's on my master page). I need to be able to display a message which says something to the effect of "Sorry...

How to search database then return results to a Gridview or other display ?
 I can connect to my datasource and by adding a gridview or other I can fill it when running the page.  Now what I have done is added a text box and button to the page. I want someone to be able to enter say a vendor # and click the button and fill the gridview or other.   I need to know how to assosicate the text box to the field of the table I am searching as well as how to pull the results back and display them?    I remember there was and old video in here that showed how it was done but its been long replaced by newer tutorials.Mike Dibble Hi, take a look ...

Display different search results in one gridview
I have a grid view that called by a SP(usp_FindrecordbychecknumID -- The sp will return the matching result based on the passing value ( either Check # or Id)  ) There are two text boxes and submit buttons ( search by check # and search by ID ) on the ASP.net page. If a user type a check #   in the “ Search by Check #” text box and click submit button, the matching records in a gridview will be displayed ( it works same way for “Search by ID” text box ). The SP is working fine, but on the ASP page when I click the submit button( either...

problem displaying advance search result into gridview
hi all i tried a few example from the previous post.. why it did not work for me.. can anybody give me the hint on how to solve my problem    Which post are you referring to? i'm refering the post on "display the search result into gridview" can you give us the link ?   http://forums.asp.net/t/1322600.aspx when i click on "search button"..nothing appear Hi syud_zack , I suggest you to have a look at this link which can teach you how to do this step by step : http://www.exforsys.com/tutorials/asp.net-2.0/asp.net-2.0-gridvi...

Display result from search with gridview only when the button is pressed
I trying to make a search function for my page.How can I start the page without showing the gridview (the data in the database). The gridview should write out the result from the search, when the button is pushed. Set the visible property of the GridView to False in the GridView declaration. Then in the Click handler, you would set the GridView.Visible back to True if you have search results to display.Mike Banavige~~~~~~~~~~~~Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/ Of course..thanks!!! I get errors on the syntax, whats w...

How to Search an SQL Server Database and Display Results in a Gridview
I am trying to create a web application that has a search function. I would like to search the database with the text that the user inputs into the TextBox and then display the results in a GridView. I would also like to split up the value if the user where to type in multiple strings.  For Example:  "chicken sausage beef" and then search the database for those 3 separate strings.. Can anyone help me accomplish this?  Hi, I give split function.CREATE PROCEDURE dbo.sp_Txt_Split( @sInputList varchar(8000) -- List of delimited items , @Delimiter c...

Sharepoint search-'How to provide 'Display more results' link in sharepoint search result core webpart.
 Hi,Currently i am working with sharepoint search result presentation.I am dealing with search core result webpart.My requirement is , i need to show top five results and then need to show 'X more results' link.when user clicks on this remaining results should displayed. Can anybody help me on this? Regards,Hina.  Hi Hina,             We have a paging option in Dataview Properties.i hope you know this already..Goto webpart Dataview Properties, in paging pane. Set " Display Items in the set of size " to '5 '..then you...

Displaying Search String Results in GridView using String Array
I created a .aspx page with a search function to look for records in the database based on the keyword the user inputs into the textbox and then display the results in a gridview when the user clicks the submit button.  As of right now I have setup an SQLDataSource on the page that runs the following query:SELECT * FROM [recipe] WHERE ([keyword] LIKE '%' + @keyword + '%') I also setup an event handler for the Button1_Click event to set the SQLDataSource I created as the DataSource for the GridView and then did a Databind();protected void Button1_Click(object send...

Use Search button on one page and display results in gridview on second page
Hello! I am wanting to do a search button on website. I have a "Search button" and a textbox where users will enter their information. After they hit the search button, I would like for them to nagviate to the "SearchResults.aspx" page where the results will be displayed in a gridview. I will be ONLY searching on one table called "Requests" where one of the columns is named "Summary"....i just need to search within the summary column basically. How would I go about doing this? Your help is very much appreciated! Thanks :-)"People will mainly...

Menu control is displaying behind Gridview control
I have placed a menu control just above the gridview control but when i click the menu control it displaysome of the menu options and rest of the menu options display behind the gridview.Is there anyway any option which make the menu to display over gridview.Mark as answer if anybody's post has helped you Typically the ZIndex will control that: http://www.w3schools.com/Css/pr_pos_z-index.aspDavid Kiffhttp://DavidKiff.co.uk-- "Mark As Answer" If my reply helped you --...

Web resources about - Displaying randomised search results in GridView - asp.net.presentation-controls

List of mammals displaying homosexual behavior - Wikipedia, the free encyclopedia
For these mammals, there is documented evidence of homosexual behavior of one or more of the following kinds: sexual behavior , courtship , affection ...

Facebook Displaying Page Insights On Page Admins’ Personal Pages?
Some Facebook page administrators are seeing modules on their personal pages displaying page insights ad, campaign , and like totals for pages ...

Facebook Displaying Unread Messages from Pages in a New Updates Module
Facebook is displaying a new “Updates” sidebar module which shows some users unread messages sent to them by Pages. Users will see the Updates ...

Don Lemon Holds Up Sign Displaying the N-Word, Uncensored, on Air CNN Live - YouTube
Don Lemon Holds Up Sign Displaying the N-Word, Uncensored, on Air Lemon held up a Confederate flag first before holding up the sign. He asked, ...

Hazelwood coal mine fire: Morwell residents displaying symptoms similar to cigarette smokers, expert ...
An expert says some locals near Victoria's Hazelwood mine fire have symptoms similar to cigarette smokers.

Police accused of displaying fake G20 weapons
Toronto's top police officer misled the public by displaying fake weapons used in a medieval-themed role-playing game to help justify their actions ...

No charges for U.S. host for displaying high-capacity magazine on TV
NBC television journalist David Gregory won't face charges for displaying a high-capacity ammunition magazine on his "Meet the Press" news program ...

Jays' Escobar suspended three games for displaying slur
Toronto Blue Jays shortstop Yunel Escobar has been suspended three games for displaying a homophobic slur on his eye-black during a game on Saturday. ...

Google Play Store now displaying age-based ratings
We reported back in May that Google was adding age-based ratings to all apps in the Play Store as determined by the International Age Rating ...

Apple displaying Ferraris & other cars at WWDC hinting at CarPlay announcements
... 2014 Filed under: AAPL Company , iOS Continue reading more about AAPL Company and iOS at 9to5Mac . What do you think? Discuss "Apple displaying ...

Resources last updated: 11/28/2015 1:22:48 AM