none
How to implement search in spgridview

    Question

  • Hello

    I am creating a custom page using spgridview where I am allowing user to add/updating/deleting contents using textboox. It seems to be working fine. Now I want to user to allow search feaure in spgridview. Lets say in spgridview I have 3 column, EMPID, Name, City, I want to allow search on EMPID, so if user enter empid and it search in the employee list and display the name and city in their corresponding columns in spgrid. How can I do this?

    Secondly is this possible to implement spellchecker functionality in spgridview?

    Saturday, July 28, 2012 8:16 AM

Answers

All replies

  • Hello,

    You can use the caml query to get the result using EMPID,

    Here is the code use this code inside your search button click event

    public void GetRecordFromEmployeeID()
    		{
    			using (SPSite site = new SPSite("http://yourserver:1111/"))
    			{
    				using (SPWeb web = site.OpenWeb())
    				{
    					SPList list = web.Lists["cust3"];
    					string EMPID = "2";
    					string strQurty = @"<Where>
    												<Eq>
    													<FieldRef Name='EmpID' />
    													<Value Type='Text'>" + EMPID + @"</Value>
    												</Eq>												
    										
    										</Where>";
    					SPQuery query = new SPQuery();
    					query.Query = strQurty;
    					query.ViewFields = string.Concat(
    									"<FieldRef Name= 'EmpID'/>",
    								   "<FieldRef Name= 'Name' />",
    								   "<FieldRef Name= 'City' />");
    					DataTable dt = list.GetItems(query).GetDataTable();
    				}
    			}
    		}

    Here you are getting the DataTable value , so use this DataTable value to bind your gridview inside your search button click event


    Hiren Patel | Please click "Propose As Answer" if this post solves your problem or "Vote As Helpful" if this post has been useful to you.



    • Edited by Hiren.j.Patel Saturday, July 28, 2012 8:27 AM
    • Proposed as answer by Aviw_ Sunday, July 29, 2012 9:19 AM
    Saturday, July 28, 2012 8:25 AM
  • Thanks Hiten.j.patel.

    Can you please share the GetDataTable code or complete code including .asxp and .cs if it is not against your ethics?



    • Edited by Avian123 Saturday, July 28, 2012 8:53 AM
    Saturday, July 28, 2012 8:52 AM
  • Hi Avian123,

    GetDataTable is the OOTB Method.

    You dont have to seperately implement this.

    Just copy paste the code it should work.

    Thanks,

    Sudan.

    Saturday, July 28, 2012 8:59 AM