Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,208,858 members, 8,004,073 topics. Date: Saturday, 16 November 2024 at 08:22 AM |
Nairaland Forum / Science/Technology / Programming / ASP.NET HELP!¡! Any Programmer Can Give Suggestion. (974 Views)
Pls Programmer Can Any Help About Java Toturial / ATM Card POS Devices (any Programmer) / A Good JAVA Programmer Can Earn As Much As #200,000 In Salary. Learn JAVA Today (2) (3) (4)
ASP.NET HELP!¡! Any Programmer Can Give Suggestion. by osarcho: 8:51am On Jun 15, 2015 |
Please I need your help concerning a program of mine, I have a database with a table in which a list of words on my site, and the page they appear in is, a page with a textbox, a button and a datalist. The purpose is to enter a group of words in the textbox, separated by a space, then each word is searched in a table in my database, and the page(s) where the words appear is returned, and saved into a List<className> I created for this, now my problem is how do I return only the page where all words in the textbox appears in order to populate the datalist. cc: Raypawer, ilekky, satindersingh1, dmayor7, avosoft, basbone, xtremrules, gimakon, blenyo11, francis164 |
Re: ASP.NET HELP!¡! Any Programmer Can Give Suggestion. by blenyo11(m): 9:47am On Jun 15, 2015 |
Pass your URL list and search term to this function public List<string> Search(List<string> allUrls, string searchTerm) { var result = new List<string>(); var wordList = searchTerm.Split(' '); //loop through all the urls foreach (var url in allUrls) { //lets create a flag for tracking var addUrl = true; //loop through the word list foreach (var word in wordList) { //if this word is not in the url; don't add this url //so let's set our flag to false if(!url.Contains(word)) addUrl = false; } //if addUrl is true then all the words are in the url. so add the url to our result if(addUrl) result.Add(url); } return result; } 1 Like |
Re: ASP.NET HELP!¡! Any Programmer Can Give Suggestion. by Nobody: 9:49am On Jun 15, 2015 |
osarcho: You have to bind your grid view to a data source, and a text box too. Then ask your text box to search. From the database, when it does it should return your data to the asp.net page. Learn data binding |
Re: ASP.NET HELP!¡! Any Programmer Can Give Suggestion. by osarcho: 10:43am On Jun 15, 2015 |
blenyo11: Nice, it works, but it is being affected by the position of the word |
Re: ASP.NET HELP!¡! Any Programmer Can Give Suggestion. by xtremrules(m): 7:47pm On Jun 15, 2015 |
osarcho:Assuming you are using Linq to Query your database and the Table name is Pages with a column called PageContents where the content of each page is saved and its Class representation is called Page, you will something like this: if The data in the textbox is saved in a variable called searchData; string[] searchArray = searchData.Split(); //Returns a substring using the default space separator //Assuming Pages is a List of pages data from Database var result = Pages.Where(x => searchArray.All(y => x.PageContents.ToLower().Contains(y.ToLower()))).ToList(); //The Above variable returns is collections of Pages( List<Pages> ) that has exactly all search strings. you can manipulate the collection the way you wish. replace .FirstOrDefault() if you want just want a Page class result 1 Like |
Re: ASP.NET HELP!¡! Any Programmer Can Give Suggestion. by osarcho: 6:02am On Jun 16, 2015 |
xtremrules: Tanx, dat should work...Ill try it |
Re: ASP.NET HELP!¡! Any Programmer Can Give Suggestion. by osarcho: 3:43pm On Jun 16, 2015 |
xtremrules: to my surprise, it only works for one word searches |
Re: ASP.NET HELP!¡! Any Programmer Can Give Suggestion. by osarcho: 4:28pm On Jun 16, 2015 |
xtremrules: This was wha I came up with at first, dunno why it's not workin: foreach (eachWord PageData in Page)It still brings out result according to the position of the word in the text box even though I tried to cater for that in if (searchQuery == txtSearch.Text.Split().Length) |
Re: ASP.NET HELP!¡! Any Programmer Can Give Suggestion. by xtremrules(m): 10:25pm On Jun 16, 2015 |
osarcho: I don't think it should. Try running this code: var searchString = "what a cool momnet here"; var stringArray = searchString.Split(); var PagesContents = new List<string>(){ "what a day to take to", "within attraction", "cool day down here", "really hot here", "Flying is easy", "Zincoxide for... none for them", "what a cool momnet with her here", "for all persons in a given house" }; var result1 = PagesContents.Where(x => stringArray.All(y => x.ToLower() .Contains(y.ToLower()))).ToList(); var result2 = PagesContents.Where(x => stringArray.Any(y => x.ToLower() .Contains(y.ToLower()))).ToList(); Console.WriteLine("From Result 1" result1.ForEach(x => Console.WriteLine(x)); Console.WriteLine("\n\nFrom Result 2 \n" result2.ForEach(x => Console.WriteLine(x)); result1 has only one result due to the .All() Linq Extension, but using .Any() returns any string that has at least one character match. so use result1 method if you want exact match and two if you want any character match. if this doesn't do want you expected you might have to explain what you really wish to do in details. You might want to download the program code.
|
(1) (Reply)
How Much House Can I Afford As A Blogger / How Can I Put Advert After First Post In Message(without Mods) In SMF / Where Can I Find A Mobile Payment API
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 34 |