DataView RowFillter之类的运算子

编程入门 行业动态 更新时间:2024-10-22 09:41:02
本文介绍了DataView RowFillter之类的运算子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在dataview rowfilter中遇到小问题.如何在dataview rowfilter.i中处理文本框为空的值,我在此过滤器中使用OR运算符.请帮助指导我这个问题.到目前为止,我使用下面的代码.

i am facing small issue in dataview rowfilter. How to handle textbox empty value in dataview rowfilter.i am using OR operator in this filter. Please help Guide me in this issue.so far i using below code.

Column1 = string.IsNullOrEmpty(txtColumn1.Text) ? "" : "%" + txtColumn1.Text + "%"; Column2 = string.IsNullOrEmpty(txtColumn2.Text) ? "" : "%" + txtColumn2.Text + "%"; Column3 = string.IsNullOrEmpty(txtColumn3.Text) ? "" : "%" + txtColumn3.Text + "%"; dataView.RowFilter = @"Column1 like '" + Column1 + "'" + "OR Column2 like '" + Column2 + "'" + "OR Column3 like '" + Column3 + "'";

推荐答案

以下代码段将帮助您控制空值过滤.尝试尝试并标记答案(如果有用)

The below code snippet will help you to control filtering with empty values. Plase try and mark the answer if it useful

StringBuilder filter = new StringBuilder(); if (!(string.IsNullOrEmpty(textBox1.Text))) filter.Append("Column1 Like '%" + textBox1.Text + "%'"); if (!(string.IsNullOrEmpty(textBox2.Text))) { if (filter.Length > 0) filter.Append(" OR "); filter.Append("Column2 Like '%" + textBox2.Text + "%'"); } if (!(string.IsNullOrEmpty(textBox3.Text))) { if (filter.Length > 0) filter.Append(" OR "); filter.Append("Column3 Like '%" + textBox3.Text + "%'"); } DataView dv = dt.DefaultView; dv.RowFilter = filter.ToString();

更多推荐

DataView RowFillter之类的运算子

本文发布于:2023-10-14 22:21:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492382.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:DataView   RowFillter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!