Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP ASP.NET
Hi to all..
i am using asp.net with sql database and my question is that
 
i have 5 text boxes...
 
Enter UId ...... textBox1
Enter Name.....textBox2
Enter City/Village .....textBox3
Enter State ....TextBox4
Enter Country ....TextBox5
button for search
(it depends on user how many entries he fills out of five textboxes)
i want to implement search in my page in a manner that search result come on behalf of data entered in textboxes by User..(he select all information of user from table where search matches)
 
for eg:-
if he enter Name='raju' and State='hariyana' then result would be all Raju in state hariyana
and if he only enters State='hariyana' then results come is all user of hariyana
this types of result i want
 
i hope u can understand what i want to do
 
actually problem i am facing is that if i use permutation and combination for this then it becomes more complex and more chances of mistakes...
i think there will be a simple method for doing this.
Pls suggest frnds and thanx in advance....
Posted 12-Feb-13 23:20pm
GDdixit531
Edited 13-Feb-13 2:34am
joe_j4K
v2
Comments
Sergey Alexandrovich Kryukov at 13-Mar-13 15:40pm
   
Please stop posting non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership. And the fact you even self-accepted on formally is just outrageous, a sure way for a ban. I hope you won't do it after this warning.
 
Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
Add few lines of code to first check whether the textboxes are not null or empty.If no then append all the entered values of the text boxes with few strings and display them in a result label.
 
You might try the below:
 
protected void Button1_Click(object sender, EventArgs e)
   {
      if(!string.IsNullOrEmpty(textbox1.Text)&&(!string.IsNullOrEmpty(textbox2.Text))&&so on..check for all the text boxes)
        {
           LabelResult.Text="All"+textbox1.Text+"in City/Village"+textbox2.Text+"of state"+textbox3.Text;
 
        }
      else
          {
            write some code on the else part depending upon your logic
           }
 
   }
Hope it helps..
 
regrds
Anurag
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

This kind of functionality should be handled at database level. What you can do is:
 
1) Pass all these fields as parameters to your stored procedure.
2) Create two temporary tables(PrimaryTable and SecondaryTable) with the columns you want to return.
3) Select all the records from your original table and fill the PrimaryTable with them.
 
Now comes the good part
 
4)
if @userid <> ''
BEGIN
truncate table SecondaryTable
insert into SecondaryTable
select * from PrimaryTable where userId = @userid
truncate table PrimaryTable
insert into PrimaryTable
select * from SecondaryTable
truncate table SecondaryTable
END
 

--Repeat till you have non-blank parameters.
 
This is just a sample. The idea is to return all the rows without any condition then based on each non-blank parameter, The records are selected from PrimaryTable to SecondaryTable, Empty PrimaryTable and Replace the records with filtered records, Empty the SecondaryTable. This whole process goes on for all the parameters. In the end return PrimaryTable.
 
Give it a try and tell if it is of any use for you?
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 295
1 OriginalGriff 214
2 BillWoodruff 170
3 Zoltán Zörgő 165
4 Maciej Los 113
0 OriginalGriff 7,760
1 DamithSL 5,874
2 Sergey Alexandrovich Kryukov 5,444
3 Maciej Los 5,076
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 16 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100