如何为 gridview 提供多个控件?
例如,我有一个网格视图和两个文本框。
一个文本框用于输入要搜索的文本。 第二个文本框是要搜索的订单号。
我希望我的 gridview 根据其中之一进行填充。我不知道如何告诉我的表单,如果用户正在使用数字搜索,如果是名称,则按名称搜索。
感谢您的任何帮助。
For example, I have a gridview and two textboxes.
One textbox is for the text to search for.
The second textbox is an order number to search for.
I want my gridview to populate based on one or the other. I don't know how to tell my form if the user is using a number search by that and if a name, instead search by that.
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,希望你还没有解决这个问题,因为我花了几分钟想出了一个例子,我认为它几乎可以满足你的要求。
DB 访问使用存储过程,但您可以将 ObjectDataSource 与 DAL 一起使用,或者仅在 SqlDataSource 上内联 SQL 语句等。
标记:
以及用于查询的 T-SQL:
如果用户未在任一字段中输入任何内容,由于
SqlDataSource.CancelSelectOnNullParameter = False
,SqlDataSource 仍将绑定,但由于设置了ControlParameter.DefaultValue
,空参数不会随查询一起发送。然后,存储过程会将 NULL 值插入到参数中,并基本上跳过 WHERE 子句中的该部分过滤。希望这有帮助。
OK hope you haven't solved this yet because I took a few minutes to come up with an example that I think will do pretty much what you want.
DB access uses a stored procedure but you can use a ObjectDataSource with DAL, or just inline the SQL statement on the SqlDataSource, etc.
Markup:
And T-SQL for your query:
If the user doesn't enter anything in either of the fields, the SqlDataSource will still bind due to
SqlDataSource.CancelSelectOnNullParameter = False
but the empty parameter will not be sent with the query due toControlParameter.DefaultValue
being set. The stored procedure will then insert the NULL value into the parameter and basically skip that part of the filtering in the WHERE clause.Hope this helps.
您可以使用 (TextBox1.Text.Trim.Length > 0) 或 (TextBox1.Text = "") 检查文本框
You can check the textboxes by using (TextBox1.Text.Trim.Length > 0) or (TextBox1.Text = "")
听起来您真正要问的是如何根据多个可能的过滤参数来过滤数据源。解释这一点需要知道您的数据源是什么。不管怎样,gridview 只会显示过滤后的结果,对吗?
如果您使用 SQL 作为数据源,该技术将与过滤内存中的集合完全不同。因此,更多有关这方面的信息将会有所帮助。
It sounds like what you are really asking is how do you filter your data source based on more than one possible filter parameter. Explaining that would require knowing what your data source is. Either way, the gridview is just going to display the filtered results, right?
If you are using SQL for your data source the technique is going to be totally different than filtering a collection in memory. So more information on that would be helpful.