ASP.net代码解释
ProtectedSubLinkButton5_Click(ByValsenderAsObject,ByValeAsSystem.EventArgs)IfDropDown...
Protected Sub LinkButton5_Click(ByVal sender As Object, ByVal e As System.EventArgs)
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
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
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 展开
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
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
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 展开
4个回答
展开全部
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//结束判断
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//结束判断
展开全部
这段代码是要就是根据下拉列表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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询