本文介绍了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之类的运算子
发布评论