Click here to Skip to main content
15,894,106 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have the tableVDC with 4000 records and its displayed in aspx page in a grid view.
I have also added the textbox to search the VDC and the search button. Now, I want to search the data from the grid when user input some text in the textbox and press search button. I am not able to do so, any suggestions would be appreciated.
Posted
Comments
Thanks7872 17-Sep-13 5:03am    
If many others can,why can't you? Can you explain this line: I am not able to do so
Adrishya 18-Sep-13 0:51am    
Mr. Rohan,

The statement I am not able to do so means, I am the beginner in programming and I tried to do it in many methods, but not able to solve the solution.
Thanks7872 18-Sep-13 0:55am    
Than you are suppose to show that "many methods". So that some one can correct it.
Adrishya 18-Sep-13 1:13am    
MEthod 1




odsVDC.FilterExpression = "";
if (txtSearchText.Text != "")
{
switch (ddlSearchBy.SelectedValue)
{
case "VDC":
odsUser.FilterExpression = ddlSearchBy.SelectedValue + " like '" + txtSearchText.Text + "%'";
break;


}
}
grdVDC.DataBind();
ToolkitScriptManager scriptManagerRIS = (ToolkitScriptManager)Utils.SuperBaseMaster.FindControl(this.Master, "ScriptManagerRIS");
scriptManagerRIS.SetFocus(txtSearchText);

Method 2

var searchTag = txtboxVDC.Text;


CSycVDC cVDC = new CSycZone(HttpContext.Current.Request.RawUrl);

if (txtboxVDC.Text != "")
{

List lst = czone.GetAll();
var lst1 = from p in lst.Where(p=>p.Zone.Contains(searchTag)) select p;
GridView1.DataSource = lst1;
GridView1.DataBind();


}

DO you need more example what I did or this are enough ?
Thanks7872 18-Sep-13 1:27am    
Use improve question widget in your question and put this code there to make it more readable.

1 solution

You could use a simple LINQ expression:

First you should try to get the text you typed in your TextBox by defining a variable or a public property.

E.g.
C#
var searchTag = TextBox.Text;


or
C#
private string searchTag
public string SearchTag
{
   get{return this.searchTag;}
   set{this.searchTag = value;}
}



And then, create a query to find the matched entries in your table
E.g.
C#
var searchResults = from r in tableVDC where r.Contains("searchTag") select r;


Hope this helps.
 
Share this answer
 
Comments
Adrishya 18-Sep-13 0:55am    
while I tried the code, I got the following error.

Compiler Error Message: CS1936: Could not find an implementation of the query pattern for source type. 'Where' not found.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900