sql += "s_qy='" + DropDownList1.SelectedItem.Text + "'" '将上面的sql与d1选择的项名进行组合,比如D1选择的是电脑,此处sql即为select * from ss where s_qy='电脑'
Protected Sub LinkButton5_Click(ByVal sender As Object, ByVal e As System.EventArgs)//按钮单击事件
If DropDownList1.SelectedIndex = 0 And TextBox3.Text = "" And TextBox4.Text = "" Then//判断,若extBox3、4内容为空且DropDownList1处于位选择任何选项的状态下
Label3.Text = "请输入搜索关键字" //Label3的Text属性设置
Else
Dim sql As String = "select * from ss where "//查找ss表的信息,按以下条件查询
If DropDownList1.SelectedIndex > 0 Then//如果下拉菜单有选中一项
sql += "s_qy='" + DropDownList1.SelectedItem.Text + "'"//查找ss表中内容与下拉菜单内容类似的结果
If TextBox3.Text <> "" Then//若TextBox3内容不为空
sql += " and s_mz like '%" + TextBox3.Text + "%'"//查询条件为查找ss表中内容与下拉菜单内容类似并且含有TextBox3里的内容的结果
If TextBox4.Text <> "" Then
sql += " and s_js like '%" + TextBox4.Text + "'%"//同上
End If End If//结束判断
Else //若以上条件不符合(下拉菜单没有选中) 则执行下列语句
If TextBox3.Text <> "" Then //若输入框TextBox3内容不为空则执行下列
sql += "s_mz like '%" + TextBox3.Text + "%'"//查询ss表中内容与输入框TextBox3内容类似的结果
If TextBox4.Text <> "" Then //查询ss表中内容与输入框TextBox3和4内容类似的结果
sql += " and s_js like '%" + TextBox4.Text + "'%"
End If Else //若以上条件不符(TextBox3内容为空)
If TextBox4.Text <> "" Then //则按输入框TextBox4的内容进行查询
sql += "s_js like '%" + TextBox4.Text + "'%"
End If End If End If//结束判断
Session("sql") = sql//建立一个session将查询语句保存在session中
ClientScript.RegisterClientScriptBlock(System.Type.GetType("System.String"), "_error", "<script>window.open('html/ss.aspx')</sc" + "ript>")执行页面源代码中的JS脚本文件(看代码好像是弹出错误提示页面) End If//结束判断
评论|赞同3
其他3条回答
2012-02-04 09:17热心网友
三元运算符。 拿x = (document.layers) ? e.pageX : document.body.scrollLeft + event.clientX;来说吧 如果document.layers为真,x=e.pageX,否则,x=document.body.scrollLeft + event.clientX;
[提问者采纳]|评论|赞同0
If DropDownList1.SelectedIndex > 0 Then sql += "s_qy='" + DropDownList1.SelectedItem.Text + "'" If TextBox3.Text <> "" Then sql += " and s_mz like '%" + TextBox3.Text + "%'" If TextBox4.Text <> "" Then sql += " and s_js like '%" + TextBox4.Text + "'%" End If End If Else
评论|赞同0
这段代码是要就是根据下拉列表Dropdownlist1,两个文本框Textbox3和4中的填入的值来进行sql语句组合(应该是模糊查询),要考虑的情况分几种,比如(为描述方便下面简称这三个控件分别为D1,T3和T4),要考虑到以下几种情况 1、D1未选择,T3和T4均为空 2、D1已选择,T3和T4均为空 3、D1已选择,T3有内容,T4为空 。。。。。 4、D1已选择,T3和T4均有内容 等等这些 If DropDownList1.SelectedIndex = 0 And TextBox3.Text = "" And TextBox4.Text = "" Then '如果均为空由提示输入 Label3.Text = "请输入搜索关键字" Else '如果有一项不为空 Dim sql As String = "select * from ss where " '基础语句 If DropDownList1.SelectedIndex > 0 Then '如D1已经选择 sql += "s_qy='" + DropDownList1.SelectedItem.Text + "'" '将上面的sql与d1选择的项名进行组合,比如D1选择的是电脑,此处sql即为select * from ss where s_qy='电脑' If TextBox3.Text <> "" Then '同样处理T3,如果T3不为空 sql += " and s_mz like '%" + TextBox3.Text + "%'" If TextBox4.Text <> "" Then sql += " and s_js like '%" + TextBox4.Text + "'%" End If End If Else If TextBox3.Text <> "" Then sql += "s_mz like '%" + TextBox3.Text + "%'" If TextBox4.Text <> "" Then sql += " and s_js like '%" + TextBox4.Text + "'%" End If Else If TextBox4.Text <> "" Then sql += "s_js like '%" + TextBox4.Text + "'%" End If End If End If Session("sql") = sql ClientScript.RegisterClientScriptBlock(System.Type.GetType("System.String"), "_error", "<script>window.open('html/ss.aspx')</sc" + "ript>") End If