you try: 1)string sID = DropDownList1.SelectedItem.Value; string sID1 = TextBox1.Text; if(sID !="") { if(sID1=="") string sqlstr="select * from tablea where col1="+sID; else string sqlstr="select * from tablea where col1='"+sID+"' and col2="+sID1; } else string sqlstr="select * from tablea where col2="+sID1;
2.从新为DropDownList绑丁数据
给DropDownList绑定数据的语句可否示范一下?
dropdownlist.datatextfield="text"
dropdownlist.datavaluefield="value"
dropdownlist.databind
dropdownlist.datatextfield=显示的文本
dropdownlist.datavaluefield=所选择项的值
dropdownlist.databind()数据绑定
1)string sID = DropDownList1.SelectedItem.Value;
string sID1 = TextBox1.Text;
if(sID !="")
{
if(sID1=="")
string sqlstr="select * from tablea where col1="+sID;
else
string sqlstr="select * from tablea where col1='"+sID+"' and col2="+sID1;
}
else
string sqlstr="select * from tablea where col2="+sID1;
2)简单例子,直接引用:
如:BindDropDown("select * from tablea",id,mc,DropDownList1);
protected void BindDropDown(string sSQL, string sValueField, string sTextField, DropDownList dropdown)
{
SqlConnection oConn = new SqlConnection(ConnString);
oConn.Open();
SqlCommand cmd = new SqlCommand(sSQL, oConn);
SqlDataReader dr = cmd.ExecuteReader();
dropdown.DataSource = dr;
dropdown.DataValueField = sValueField;
dropdown.DataTextField = sTextField;
dropdown.DataBind();
dr.Close();
dropdown.SelectedIndex = 2;
}