日期:2014-05-17 浏览次数:20604 次
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; public partial class Default6 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string 表名 = "新闻表"; //查询[新闻表]中的指标SQL语句 string strSql = string.Format(@"select [name] from syscolumns where [id] in (select [id] from sysobjects where [type]='U' and [name]='{0}')", 表名); ddrList.DataSource = GetTable(strSql);//查询所有字段 ddrList.DataTextField = "name"; ddrList.DataValueField = "name"; ddrList.DataBind(); ddrList.Items.Insert(0, "全部"); //如果选择全部,则查询所有 } } protected void linkOK_Click(object sender, EventArgs e) { string strWhere = string.Empty; if (ddrList.SelectedValue.Equals("全部")) //如果选择 全部 所有指标查询 { //and 条件 //for (int i = 1; i < ddrList.Items.Count; i++) //i=1是去除[全部]这个指标 //{ // strWhere += string.Format(@" {0} like '%{1}%' and", ddrList.Items[i].Value, txtWhere.Text.Trim()); //拼接查询条件语句 //} //strWhere = strWhere.Substring(0, strWhere.Length - 3); //去掉最后一个and //or 条件 for (int i = 1; i < ddrList.Items.Count; i++) //i=1是去除[全部]这个指标 { strWhere += string.Format(@" {0} like '%{1}%' or", ddrList.Items[i].Value, txtWhere.Text.Trim()); //拼接查询条件语句 } strWhere = strWhere.Substring(0, strWhere.Length - 2); /