在gridveiw中如何编写搜索按钮的代码. [英] in gridveiw how to write the code for search button..

查看:59
本文介绍了在gridveiw中如何编写搜索按钮的代码.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序正在使用一个标签,一个文本框和一个搜索按钮,并且我将所有数据存储在数据库中.我正在考虑字段uid,uname,location ...如果我在文本框中输入了任何uid并按搜索按钮,则我想搜索uid,它将仅显示该特定记录,以便如何编写代码...谢谢Advance ..

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..

推荐答案

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();
        }



您可以使用以下代码,其中"GetAllRecords()"是在您的类中使用名称"yourClassName"定义的静态方法,该方法一次返回所有记录,并根据在搜索文本框中输入的值将记录绑定到您的动态网格视图.

您也可以使用sql查询来获取记录.但最好使用linq.

[edit]代码块已修复[/edit]



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]


这篇关于在gridveiw中如何编写搜索按钮的代码.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆