Description: This tutorial explains how to implement search functionality in a list without any code.
I recently had a requirement of implementing a search page for a List where user pass a search phrase via Query String (e.g. http://SharePoint2010:1000/Pages/Search.aspx?q=hello) and the search page will display the results from a List, based on that search phrase. I am excited to share the technique where one don't have to write a code to develop such page and everything can be taken care of easily via SharePoint Designer.
This technique can also be used in SharePoint 2007 via SharePoint Designer 2007. However the Data View web part's options are available on Data View context menu instead of the tool bar.
Here is the Page's code with text field and button to pass the search string to the Search.aspx page.
<script type="text/javascript">
function Redirect()
{
window.location = "http://SharePoint2010:1000/Pages/Search.aspx?q=" + document.getElementById('Text1').value;
}
</script>
<input name="Text1" type="text">
<button name="Abutton1" onclick="Redirect();">button</button>
nice article, just what I was finding! Any idea how to create a search button and textbox to pass that query string?
ReplyDeleteButton:
Deletehttp://www.w3schools.com/tags/tag_button.asp
TextBox:
http://www.w3schools.com/jsref/dom_obj_text.asp
Great tutorial, thanks a lot for sharing!
ReplyDeleteGood one. I tried and it worked. I am new to Sharepoint. What is the best way to build a front end in Sharepoint to use the parameter to this search?
ReplyDeleteIs there a tutorial that shows how to build a sharepoint page to ask for input of parameter "q" and click a submit button to start this search?
I can not past HTML code in comments here. Give me your email address and I will send you a sample HTML.
Deletesteven21761@yahoo.com
ReplyDeleteLooking forward to build my own search tool instead of using Search Center.
I have emailed you the code that will take input from the user and will redirect to the search page with "q" parameter.
DeleteHi Tahir ... useful tutorial thank you. May i also have the code you sent to steven please. My email address is richard@greensquirrel.co.uk
DeleteThanks again,
Richard
Sent.
DeleteHi Tahir. Nice tutorial. Can you please send me the code with q parameter?
DeleteBest regards
kjetil.halvorsen@posten.no
Hey Tahir, great work and thanks for the article. Can you please email me the code as well?
Deletebrian.davis@primegrp.com
Thanks! Brian
Done, Kjetil and Brian!
DeleteHi
ReplyDeletePlease could you send me the code too?
jodshay@gmail.com
Thanks
Could you send me the code as well? j.david.moore1@gmail.com
ReplyDeleteSent.
DeleteHi Tahir ... useful tutorial, many thanks. May i also have the code you sent to steven please. My email address is marc.florie@kpn.com
DeleteThanks again,
Marc
Hi Tahir.
ReplyDeleteWhen i add a filter, i dont have all the fields of my list. Is there any step that i have to do in that specific field?
and.. btw.. can you send me the HTML code to? Great tutorial!!
pauloteixeira@mail.telepac.pt
Thanks!!
Edit your view to see the field.
DeleteAlso the HTML snippet has been sent.
Hi Tahir,
ReplyDeleteExcellent tutorial! I would love a copy of the HTML code as well please, sent to eportney@gmail.com
Thank you very much!
Sent.
DeleteHello Tahir,
ReplyDeleteThanks for the excellent tutorial! I hate to ask, but could I get a copy of the HTML also?
dougg42@gmail.com
Sent
DeleteThank you very much!
DeleteTahir,
ReplyDeleteThis is very helpful! Would you please send the code my way? rcebarb407@gmail.com
Thank you so much!
The HTML code has been attached at the end of the post.
DeleteI was able to pass 2 Query String values and build an "AND" condition. i.e. SearchInvoice.aspx?Field1=abc&Field2=123
ReplyDeleteHowever, in some situations, my Field2 may be "Blank", meaning I do not need to include any condition here. So the URL becomes: SearchInvoice.aspx?Field1=abc&Field2=
When this is run, it returns NO item from SharePoint. I am hoping it will run like searching for Field1 only. I tried Field2=* but it does not work.
Any ideas to solve this problem?
I have seen this situation before and this is where you hit the limitation of DataForm webpart.
DeleteDataView's variable dont understand that if the value is null then display all records. Alternate approach is to have two DataForms webparts (1 with the filter 1 without) and with JavaScript check if the value is null display the DataView webpart without the filters and it will display all results.
Hope it helps.