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
What.
webforms or winforms?
Web forms
.aspx
oh wow that is old AF
Yeah im practicing for school but no idea how to finish this
what the dropdownlists are suppose to do?
select the file?
The program id about music albums and the dropdown lists are supposed to be used to select the genre and date of release
ah ok so its all items of your search ok
and how is the file formatted
Wdym
Sorry im a bit new
well u have data in your text file right? can u $paste it to the below site
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!
Aha yeah i can
BlazeBin - jpzpihhhkczk
A tool for sharing your source code with the world!
ok
Its got 5 columns of text and an image in the last one
And its separated by a |
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
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
so do the parts u know
then show me the code and we work on the comparing part
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
sure $paste up what u did lets investigate
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!
BlazeBin - etynfnrckoaz
A tool for sharing your source code with the world!
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
ok so line 36 is wrong
Oh right i forgot to put the |
yep
can any of your lines in the file be smaller in column size?
Changed that but it still shows the same error
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
Didnt do that
ok u know how to do it?
I did it now
Yeah
Properties
ok then try again
also the file is inside a folder called App_Data in your solution explorer right?
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
ok
so lets start it simple
change line 39 to just
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
Yeah im doing that
This did it
nice, so we know the file is being read
Now it prints the line from the txt file
Yeah
and we know it works
now add + searches to it
To line 39?
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
For example if i put the year 2008 in the dropdown list it should return the songs/albums released in 2008
sor your search is an OR search not and AND search?
Yeah it doesnt need to match everything
ok then it would be somewhat like this
Unless i put everything in
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:
so basically if the item is not empty and does not match any of the search items we skip it
Whats the year thing though?
The dropdownlist with the years?
whatever year was selected I just named it year but you use whatever yours is name
for example
My years are put in as items in the dropdownlist
selectedOccupation
Aha right
My bad
u might need to use Trim() in some of your parts because you have space around the |
Trim removes those space
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
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
then it wont matter if u type gob or Gob it will match both
I wrote it correctly
well I cannot tell I am not seeing your monitor and your code š so u need to tell me exactly
It works now
can you $paste what your code looks like so I can see
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!
Yeah
BlazeBin - fkgfdlsyfzbf
A tool for sharing your source code with the world!
line 41 should be removed
and the brackets around
can be removed 2
aside from it should work
Yup it returns it to the label
Tysm man
Helped me learn this
š
no worries
Use the /close command to mark a forum thread as answered
feel free to open a new thread if u need help