Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys.. in my application am using one label and one textbox and one search button and i have all the data in the database. am taking the fields are uid ,uname ,location... i want to search the uid if i enterd any uid in the textbox and press the search button it will display only that particular record so how to write the code... thanks in advance..
Posted
Comments
Nelek 24-Nov-12 5:20am    

1 solution

C#
protected void btnSearch_Click(object sender, EventArgs e)
        {
            List<yourclassname> lstList = yourClassName.GetAllRecords();
            var record = from rec in lstList where rec.uname == txtSearch.Text.Trim() select rec;
            grvTest.DataSource = record;
            grvTest.DataBind();
        }


you can use this code in which "GetAllRecords()"is the static method defind in your class having name "yourClassName" which return you all record at a time and based on the value entered in your search textbox the records is being bind to your grid view dynamically.

you can fetch the record by using sql query also. but it is preffer to use linq.

[edit]code block fixed[/edit]
 
Share this answer
 
v2

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