为什么不管在dropdownlist1控件中选那一项,只要点击button1按钮,得到的都是第一项的值,不点击button1的时候,测试绑定完全正常,(第一项对应第一项的值,第二项对应第二项的值.......)Imports System.Data
Imports System.Data.oledb
Public Class login1
Inherits System.Web.UI.Page#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub
Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents Button11 As System.Web.UI.WebControls.Button
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim sql As String
Dim conn As New conclass.conclass
conn.con1.Open()
sql = "select name from admin order by id"
Dim mycommand As New OleDbDataAdapter(sql, conn.con1)
Dim dataset11 As New DataSet
mycommand.Fill(dataset11, "admin")
DropDownList1.DataSource = dataset11.Tables("admin").DefaultView
DropDownList1.DataTextField = "name"
DropDownList1.DataValueField = "name"
DropDownList1.DataBind()
conn.con1.Close()
End If
'在此处放置初始化页的用户代码
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
Dim passwords1, sql As String
Dim name1 As String
passwords1 = TextBox2.Text.ToString.Trim
name1 = DropDownList1.SelectedItem.Text
If passwords1 = "" Then
Response.Write("<script language=javascript>alert('密码不得为空!!!')</script>")
Else
Dim conn As New conclass.conclass
conn.con1.Open()
sql = "select top 1 [id],[name],[password] from [admin] where [name]= '" & name1 & "' and [password]='" & passwords1 & "'"
Dim reader1 As New OleDbDataAdapter(sql, conn.con1)
Dim dataset11 As New DataSet
reader1.Fill(dataset11, "admin")
If dataset11.Tables("admin").Rows.Count = 0 Then
TextBox2.Text = ""
Session("flag") = False
Response.Write("<script language=javascript>alert('密码错误!!!')</script>")
ElseIf dataset11.Tables("admin").Rows.Count = 1 Then
Session("flag") = True
Session("users") = DropDownList1.SelectedItem.Value.ToString.Trim
Response.Redirect("adminmaillist.aspx")
End If
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
TextBox2.Text = ""
End Sub
End Class
Imports System.Data.oledb
Public Class login1
Inherits System.Web.UI.Page#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub
Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents Button11 As System.Web.UI.WebControls.Button
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim sql As String
Dim conn As New conclass.conclass
conn.con1.Open()
sql = "select name from admin order by id"
Dim mycommand As New OleDbDataAdapter(sql, conn.con1)
Dim dataset11 As New DataSet
mycommand.Fill(dataset11, "admin")
DropDownList1.DataSource = dataset11.Tables("admin").DefaultView
DropDownList1.DataTextField = "name"
DropDownList1.DataValueField = "name"
DropDownList1.DataBind()
conn.con1.Close()
End If
'在此处放置初始化页的用户代码
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
Dim passwords1, sql As String
Dim name1 As String
passwords1 = TextBox2.Text.ToString.Trim
name1 = DropDownList1.SelectedItem.Text
If passwords1 = "" Then
Response.Write("<script language=javascript>alert('密码不得为空!!!')</script>")
Else
Dim conn As New conclass.conclass
conn.con1.Open()
sql = "select top 1 [id],[name],[password] from [admin] where [name]= '" & name1 & "' and [password]='" & passwords1 & "'"
Dim reader1 As New OleDbDataAdapter(sql, conn.con1)
Dim dataset11 As New DataSet
reader1.Fill(dataset11, "admin")
If dataset11.Tables("admin").Rows.Count = 0 Then
TextBox2.Text = ""
Session("flag") = False
Response.Write("<script language=javascript>alert('密码错误!!!')</script>")
ElseIf dataset11.Tables("admin").Rows.Count = 1 Then
Session("flag") = True
Session("users") = DropDownList1.SelectedItem.Value.ToString.Trim
Response.Redirect("adminmaillist.aspx")
End If
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
TextBox2.Text = ""
End Sub
End Class
解决方案 »
- ~~```当在使用ajax的环境下,再使用Response.Write(@"<script>alert('ok')</script>")时出错
- 做过大型项目的请进,请教一些理论上的问题
- DataGrid中有一个模板列,里面有两个LinkButton,怎么知道是点是哪一行的哪一个呢?
- 公司面试试题求解,急!!!
- 关于ASP。NET的问题
- asp.net做类似搜索引擎的项目
- 一个登陆界面进入第二个界面后 把第二个界面收藏到收藏夹里面 用什么控制第二个界面在收藏夹里面打开的时候,不能打开 并且进入登陆界面
- 请教一个ASP.net的问题,在线给分!!
- 请问:怎样注册一个组件?
- 今晚的最后散分:)过一会儿要继续学了。
- asp 精彩不容错过!和大家一起分享!
- 用PagedDataSource分页带来的问题
if (Page.IsPostBack)
{
//绑定
}
点击button按钮的时候ddl被重新榜定了,所以每次取值都是第一项
不如试一下name1 = DropDownList1.Selectedvalue