C
C#ā€¢4mo ago
444mihajlo

how to search .txt file with textboxes and dropdownlists and print in a table or label vs webforms

Im trying to search data from a .txt file with textboxes and dropdownlists, then print the item i searched for in a label. I was making this in vusual studio web forms
67 Replies
leowest
leowestā€¢4mo ago
webforms or winforms?
444mihajlo
444mihajloā€¢4mo ago
Web forms .aspx
leowest
leowestā€¢4mo ago
oh wow that is old AF
444mihajlo
444mihajloā€¢4mo ago
Yeah im practicing for school but no idea how to finish this
leowest
leowestā€¢4mo ago
what the dropdownlists are suppose to do? select the file?
444mihajlo
444mihajloā€¢4mo ago
The program id about music albums and the dropdown lists are supposed to be used to select the genre and date of release
leowest
leowestā€¢4mo ago
ah ok so its all items of your search ok and how is the file formatted
444mihajlo
444mihajloā€¢4mo ago
Wdym Sorry im a bit new
leowest
leowestā€¢4mo ago
well u have data in your text file right? can u $paste it to the below site
MODiX
MODiXā€¢4mo ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
444mihajlo
444mihajloā€¢4mo ago
Aha yeah i can
444mihajlo
444mihajloā€¢4mo ago
BlazeBin - jpzpihhhkczk
A tool for sharing your source code with the world!
leowest
leowestā€¢4mo ago
ok
444mihajlo
444mihajloā€¢4mo ago
Its got 5 columns of text and an image in the last one And its separated by a |
leowest
leowestā€¢4mo ago
basically when u press your button it needs to do the following 1) have a list to hold the result of the search 2) readalllines of the file 3) loop the lines 4) split the line by | 5) compare the column to the search items and look for a match 6) add items that match to the list 7) return the list to your result location in your case the label does that make sense to u? which items do u know how to do and which u dont
444mihajlo
444mihajloā€¢4mo ago
I know how to return the text to the label, i know the File.ReadAllLines, and im pretty sure i can do the split, just not sure how to do the search and compare part
leowest
leowestā€¢4mo ago
so do the parts u know then show me the code and we work on the comparing part
444mihajlo
444mihajloā€¢4mo ago
So i did something, and it does return to the label, but it returns an error, "couldnt find a part of the path" Im assuming it just has to do with the file location and path, and that the code is okay
leowest
leowestā€¢4mo ago
sure $paste up what u did lets investigate
MODiX
MODiXā€¢4mo ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
444mihajlo
444mihajloā€¢4mo ago
BlazeBin - etynfnrckoaz
A tool for sharing your source code with the world!
444mihajlo
444mihajloā€¢4mo ago
I also tried just dragging the .txt file into where the path needs to be but it wont let me, and right clickig on it, then copying full path and pasting it also doesnt work
leowest
leowestā€¢4mo ago
ok so line 36 is wrong
444mihajlo
444mihajloā€¢4mo ago
Oh right i forgot to put the |
leowest
leowestā€¢4mo ago
yep can any of your lines in the file be smaller in column size?
444mihajlo
444mihajloā€¢4mo ago
Changed that but it still shows the same error
leowest
leowestā€¢4mo ago
if not u dont need to check the Length yeah I am just pointing what is wrong for now besides that it all looks good u did great so lets figure out the file issue in your solution explorer did u set your file properties to copy if newer? the textfile with the songs
444mihajlo
444mihajloā€¢4mo ago
Didnt do that
leowest
leowestā€¢4mo ago
ok u know how to do it?
444mihajlo
444mihajloā€¢4mo ago
I did it now Yeah Properties
leowest
leowestā€¢4mo ago
ok then try again also the file is inside a folder called App_Data in your solution explorer right?
444mihajlo
444mihajloā€¢4mo ago
Same thint Yeah I just removed the folder And put only the file And now theres no error But It says no matching data found
leowest
leowestā€¢4mo ago
ok so lets start it simple change line 39 to just
if (parts[0].Contains(searchText))
if (parts[0].Contains(searchText))
also keep in mind that Contains is not taking into account upper and lower case so u need to write exact match i.e.: Gob and not gob
444mihajlo
444mihajloā€¢4mo ago
Yeah im doing that This did it
leowest
leowestā€¢4mo ago
nice, so we know the file is being read
444mihajlo
444mihajloā€¢4mo ago
Now it prints the line from the txt file Yeah
leowest
leowestā€¢4mo ago
and we know it works now add + searches to it
444mihajlo
444mihajloā€¢4mo ago
To line 39?
leowest
leowestā€¢4mo ago
well it depends how do u want to search? like for example if I type something in the song name and select the year do u want it to search for songs that contain that search and match the year or songs that contain that name or year
444mihajlo
444mihajloā€¢4mo ago
For example if i put the year 2008 in the dropdown list it should return the songs/albums released in 2008
leowest
leowestā€¢4mo ago
sor your search is an OR search not and AND search?
444mihajlo
444mihajloā€¢4mo ago
Yeah it doesnt need to match everything
leowest
leowestā€¢4mo ago
ok then it would be somewhat like this
444mihajlo
444mihajloā€¢4mo ago
Unless i put everything in
leowest
leowestā€¢4mo ago
so what I would do is set an bool outside the foreach set to false and have separated ifs per search items ops ok wait bit mistake for example:
foreach .... rest of code
{
.... rest of code
if (!string.IsNullOrEmpty(searchText) && !parts[0].Contains(searchText))
{
continue;
}

if (!string.IsNullOrEmpty(year) && year != parts[3])
{
continue;
}

... update label with line
}
foreach .... rest of code
{
.... rest of code
if (!string.IsNullOrEmpty(searchText) && !parts[0].Contains(searchText))
{
continue;
}

if (!string.IsNullOrEmpty(year) && year != parts[3])
{
continue;
}

... update label with line
}
so basically if the item is not empty and does not match any of the search items we skip it
444mihajlo
444mihajloā€¢4mo ago
Whats the year thing though? The dropdownlist with the years?
leowest
leowestā€¢4mo ago
whatever year was selected I just named it year but you use whatever yours is name for example
444mihajlo
444mihajloā€¢4mo ago
My years are put in as items in the dropdownlist
leowest
leowestā€¢4mo ago
selectedOccupation
444mihajlo
444mihajloā€¢4mo ago
Aha right My bad
leowest
leowestā€¢4mo ago
if (!string.IsNullOrEmpty(selectedOccupation) && selectedOccupation != parts[2].Trim())
if (!string.IsNullOrEmpty(selectedOccupation) && selectedOccupation != parts[2].Trim())
u might need to use Trim() in some of your parts because you have space around the | Trim removes those space
444mihajlo
444mihajloā€¢4mo ago
The dropdownlists seem to work now, but when i write the name in the 1st list it doesnt return the one i wrote, it returns another one
leowest
leowestā€¢4mo ago
and how u wrote the name in the search box if u want your search to ignore case then u would need to use the parameter of Contains StringComparison
Contains(name, StringComparison.InvariantCultureIgnoreCase)
Contains(name, StringComparison.InvariantCultureIgnoreCase)
then it wont matter if u type gob or Gob it will match both
444mihajlo
444mihajloā€¢4mo ago
I wrote it correctly
leowest
leowestā€¢4mo ago
well I cannot tell I am not seeing your monitor and your code šŸ™‚ so u need to tell me exactly
444mihajlo
444mihajloā€¢4mo ago
It works now
leowest
leowestā€¢4mo ago
can you $paste what your code looks like so I can see
MODiX
MODiXā€¢4mo ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
444mihajlo
444mihajloā€¢4mo ago
Yeah
444mihajlo
444mihajloā€¢4mo ago
BlazeBin - fkgfdlsyfzbf
A tool for sharing your source code with the world!
leowest
leowestā€¢4mo ago
line 41 should be removed and the brackets around
Label6.Text += line + "<br/>";
Label6.Text += line + "<br/>";
can be removed 2 aside from it should work
444mihajlo
444mihajloā€¢4mo ago
Yup it returns it to the label Tysm man Helped me learn this šŸ˜ƒ
leowest
leowestā€¢4mo ago
no worries
MODiX
MODiXā€¢4mo ago
Use the /close command to mark a forum thread as answered
leowest
leowestā€¢4mo ago
feel free to open a new thread if u need help
Want results from more Discord servers?
Add your server
More Posts
cant set enhanced mouse precisionOk i still donā€™t have the mouse thing working. Iā€™m trying to set the enhanced mouse position option Create JSON objects from System.Text.JsonFor a while now I've been trying to get away from dependencies that I don't need anymore, including How to change the button output. Instead of questions it should show some more buttons.``` using System; using System.Linq; using NativeUiLib; //This ads the GUI contols. Minor abstractio.NET 8 error when using ASP.NET AspNetCore.Reporting.LocalReport`var result = localReport.Execute(AspNetCore.Reporting.RenderType.ExcelOpenXml, 1, param, "");` Errcan we send extra data in .net8 identity endpointsi need to send some extra data add the time of register. this register end point only allow email anHelp with Switching Views using MVVMhttps://github.com/MasonOderSo/MVVMtesting I have no idea why this is not working it is working in Help me with my concurrency experimentsCorrect me if I'm wrong. Based on my understanding, a CPU with 1 core running 1 thread has the same Create Migration always failSo I wanted to create a SQL Server database table based on your C# model. I have typed down `dotnetSynchronous Chat ProgramI'm doing this assignment that's due tomorrow and i don't know what im doing. basically i need to maDynamic channel/queue system where only one unit of a particular group can process at any given timeHello all. For a specific requirement, I need to build a channel/queue system for units of work, whe