C
C#ā€¢10mo 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
The Fog from Human Resources
What.
leowest
leowestā€¢10mo ago
webforms or winforms?
444mihajlo
444mihajloOPā€¢10mo ago
Web forms .aspx
leowest
leowestā€¢10mo ago
oh wow that is old AF
444mihajlo
444mihajloOPā€¢10mo ago
Yeah im practicing for school but no idea how to finish this
leowest
leowestā€¢10mo ago
what the dropdownlists are suppose to do? select the file?
444mihajlo
444mihajloOPā€¢10mo 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ā€¢10mo ago
ah ok so its all items of your search ok and how is the file formatted
444mihajlo
444mihajloOPā€¢10mo ago
Wdym Sorry im a bit new
leowest
leowestā€¢10mo ago
well u have data in your text file right? can u $paste it to the below site
MODiX
MODiXā€¢10mo 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
444mihajloOPā€¢10mo ago
Aha yeah i can
444mihajlo
444mihajloOPā€¢10mo ago
BlazeBin - jpzpihhhkczk
A tool for sharing your source code with the world!
leowest
leowestā€¢10mo ago
ok
444mihajlo
444mihajloOPā€¢10mo ago
Its got 5 columns of text and an image in the last one And its separated by a |
leowest
leowestā€¢10mo 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
444mihajloOPā€¢10mo 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ā€¢10mo ago
so do the parts u know then show me the code and we work on the comparing part
444mihajlo
444mihajloOPā€¢10mo 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ā€¢10mo ago
sure $paste up what u did lets investigate
MODiX
MODiXā€¢10mo 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
444mihajloOPā€¢10mo ago
BlazeBin - etynfnrckoaz
A tool for sharing your source code with the world!
444mihajlo
444mihajloOPā€¢10mo 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ā€¢10mo ago
ok so line 36 is wrong
444mihajlo
444mihajloOPā€¢10mo ago
Oh right i forgot to put the |
leowest
leowestā€¢10mo ago
yep can any of your lines in the file be smaller in column size?
444mihajlo
444mihajloOPā€¢10mo ago
Changed that but it still shows the same error
leowest
leowestā€¢10mo 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
444mihajloOPā€¢10mo ago
Didnt do that
leowest
leowestā€¢10mo ago
ok u know how to do it?
444mihajlo
444mihajloOPā€¢10mo ago
I did it now Yeah Properties
leowest
leowestā€¢10mo ago
ok then try again also the file is inside a folder called App_Data in your solution explorer right?
444mihajlo
444mihajloOPā€¢10mo 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ā€¢10mo 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
444mihajloOPā€¢10mo ago
Yeah im doing that This did it
leowest
leowestā€¢10mo ago
nice, so we know the file is being read
444mihajlo
444mihajloOPā€¢10mo ago
Now it prints the line from the txt file Yeah
leowest
leowestā€¢10mo ago
and we know it works now add + searches to it
444mihajlo
444mihajloOPā€¢10mo ago
To line 39?
leowest
leowestā€¢10mo 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
444mihajloOPā€¢10mo ago
For example if i put the year 2008 in the dropdown list it should return the songs/albums released in 2008
leowest
leowestā€¢10mo ago
sor your search is an OR search not and AND search?
444mihajlo
444mihajloOPā€¢10mo ago
Yeah it doesnt need to match everything
leowest
leowestā€¢10mo ago
ok then it would be somewhat like this
444mihajlo
444mihajloOPā€¢10mo ago
Unless i put everything in
leowest
leowestā€¢10mo 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
444mihajloOPā€¢10mo ago
Whats the year thing though? The dropdownlist with the years?
leowest
leowestā€¢10mo ago
whatever year was selected I just named it year but you use whatever yours is name for example
444mihajlo
444mihajloOPā€¢10mo ago
My years are put in as items in the dropdownlist
leowest
leowestā€¢10mo ago
selectedOccupation
444mihajlo
444mihajloOPā€¢10mo ago
Aha right My bad
leowest
leowestā€¢10mo 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
444mihajloOPā€¢10mo 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ā€¢10mo 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
444mihajloOPā€¢10mo ago
I wrote it correctly
leowest
leowestā€¢10mo ago
well I cannot tell I am not seeing your monitor and your code šŸ™‚ so u need to tell me exactly
444mihajlo
444mihajloOPā€¢10mo ago
It works now
leowest
leowestā€¢10mo ago
can you $paste what your code looks like so I can see
MODiX
MODiXā€¢10mo 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
444mihajloOPā€¢10mo ago
Yeah
444mihajlo
444mihajloOPā€¢10mo ago
BlazeBin - fkgfdlsyfzbf
A tool for sharing your source code with the world!
leowest
leowestā€¢10mo 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
444mihajloOPā€¢10mo ago
Yup it returns it to the label Tysm man Helped me learn this šŸ˜ƒ
leowest
leowestā€¢10mo ago
no worries
MODiX
MODiXā€¢10mo ago
Use the /close command to mark a forum thread as answered
leowest
leowestā€¢10mo ago
feel free to open a new thread if u need help
Want results from more Discord servers?
Add your server