1个回答
展开全部
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; } }
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询