求asp.net 中多条件模糊查询代码(全)

查询(Button)内的详细代码带注释更好谢谢... 查询( Button)内的详细代码 带注释更好 谢谢 展开
 我来答
宽御垒1458
2014-07-01 · 超过57用户采纳过TA的回答
知道答主
回答量:114
采纳率:100%
帮助的人:101万
展开全部
using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class Search : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } private string getSafestring(string s) { s = s.Trim(); s = s.Replace("'","''"); s = s.Replace("\"", ""); s = s.Replace("%", ""); s = s.Replace("--", ""); s = s.Replace(";", ""); s = s.Replace("(", ""); s = s.Replace(")", ""); s = s.Replace("-", ""); return s; } protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { ConnectionFactory cf = new ConnectionFactory(); string sql = "select * from v_topic"; string key = ""; if (TextBox1.Text != "") key = "topicname like '%" + getSafestring(TextBox1.Text) + "%'"; if (Checkshowhide.Checked) { if (TextBox2.Text != "") { if (key == "") key = "uid like '%" + getSafestring(TextBox2.Text) + "%'"; else key += " and uid like '%" + getSafestring(TextBox2.Text) + "%'"; } if (RadioButton2.Checked) { if (key == "") key = "state=1"; else key += " and state=1"; } if (RadioButton3.Checked) { if (key == "") key = "state=2"; else key += " and state=2"; } if (DropDownList1.SelectedItem.Text != "全部时间") { if (RadioButton4.Checked) { if (key == "") key = "emittime > '" + DateTime.Now.AddDays(-int.Parse(DropDownList1.SelectedValue)) + "'"; else key += " and emittime > '" + DateTime.Now.AddDays(-int.Parse(DropDownList1.SelectedValue)) + "'"; } else { if (key == "") key = "emittime < '" + DateTime.Now.AddDays(-int.Parse(DropDownList1.SelectedValue)) + "'"; else key += " and emittime < '" + DateTime.Now.AddDays(-int.Parse(DropDownList1.SelectedValue)) + "'"; } } if (RadioButton6.Checked) { key += " order by " + DropDownList2.SelectedValue; } else { key += " order by " + DropDownList2.SelectedValue + " desc"; } } if (key != "") sql += " where " + key; GridView1.DataSource = cf.getTable(sql); GridView1.DataBind(); Label7.Visible = true; Label7.Text = "共找到符合条件的数据" + GridView1.Rows.Count + "条"; Checkshowhide.Checked = false; } }
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式