使用asp.net文本框的GridView过滤 [英] Gridview filtering using textbox in asp.net

查看:179
本文介绍了使用asp.net文本框的GridView过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何搜索,或在GridView过滤器动态地记录根据字符(S)上的一个文本框输入。什么是实现这一目标的最佳途径?任何样品codeS或例子将是非常有帮助的。

i want to know as how to search or filter records in a gridview dynamically based on the character(s) entered on a textbox. What is the best way to achieve this? Any sample codes or examples will be really helpful.

推荐答案

这里的窍门是为使数据绑定唯一当文字变化对搜索框,但你必须的总是设置数据源选择命令code 。所以你添加一个文本框,一个按钮,说,提交,和你有以下内容:

The trick here is to make databind only when the text change on the search box, but you must always set the datasource select command code. So you add a text box, and a button that say, submit, and you have the following:

    OnPageLoad -> 
if(SearchContron.Text.Length > 0)
  SqlDataSource1.SelectCommand = "SELECT * FROM TABLE WHERE Desc LIKE N'%" + SearchContron.Text +"%'"
else
  SqlDataSource1.SelectCommand = "SELECT * FROM TABLE "

OnSubmitButtonClick -> GridView.DataBind()

如果你做其他的方式,分页和编辑等命令就会失败。你也可以让它更先进的,如果你从文本框中的文本和许多的话打破它和搜索每一个作为单独在同一SQL命令。

If you do it other way, the paging and editing and other commands will fail. You can also make it more advanced if you get the text from the text box and break it in many words and search each one as separate on the same sql command.

这篇关于使用asp.net文本框的GridView过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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