标题:为什么取不到dropdownlist的值
取消只看楼主
kiska3088915
Rank: 2
等 级:论坛游民
帖 子:72
专家分:12
注 册:2009-11-7
结帖率:86.96%
已结贴  问题点数:16 回复次数:5 
为什么取不到dropdownlist的值

又得来麻烦各位大虾了,如图,这是一个网站的注册页面,其他的没问题,就剩下选择生日这个功能了,一开始觉得很简单,没放心上,最后收尾工作准备把这个功能搞定的时候发现,这段代码竟然取不到3个dropdownlist被选中项的text值,        
        If DropDownList1.SelectedIndex <> 0 Then
            birthdayyear = DropDownList1.SelectedItem.Text
        End If
        If DropDownList2.SelectedIndex <> 0 Then
            birthdaymonth = DropDownList2.SelectedItem.Text
        End If
        If DropDownList3.SelectedIndex <> 0 Then
            birthdayday = DropDownList3.SelectedItem.Text
        End If
        birthday = birthdayyear + "/" + birthdaymonth + "/" + birthdayday
不论怎么弄,最后birthday的值都是“//”,很疑惑,求大虾解释
搜索更多相关主题的帖子: dropdownlist 
2010-12-01 21:10
kiska3088915
Rank: 2
等 级:论坛游民
帖 子:72
专家分:12
注 册:2009-11-7
得分:0 
回复 2楼 冰镇柠檬汁儿
报告头,看了一下,值都是“please choose”
2010-12-01 21:56
kiska3088915
Rank: 2
等 级:论坛游民
帖 子:72
专家分:12
注 册:2009-11-7
得分:0 
回复 4楼 冰镇柠檬汁儿
额,真不明白,问题是我调试时的确选择了出生年月啊,所以照理来说selectedindex不应该为0的,但是点submit的时候就是没把选中的数据读进去啊,我也不知道是怎么回事,求指教
2010-12-01 22:50
kiska3088915
Rank: 2
等 级:论坛游民
帖 子:72
专家分:12
注 册:2009-11-7
得分:0 
回复 6楼 冰镇柠檬汁儿
是.net控件
附上代码,麻烦诸位了

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim logname As String
        Dim logpsw As String
        Dim username As String
        Dim email As String
        Dim address As String
        Dim birthday As String = ""
        Dim birthdayyear As String = ""
        Dim birthdaymonth As String = ""
        Dim birthdayday As String = ""
        logname = TextBoxlogname.Text
        logpsw = TextBoxlogpassword.Text
        username = TextBoxusername.Text
        email = TextBoxemail.Text
        address = TextBoxaddress.Text
        Dim connect As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection
        connect.ConnectionString = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("App_Data/database/shopping system of ultra electronics website.mdb"))
        Dim cmd As System.Data.OleDb.OleDbCommand = New System.Data.OleDb.OleDbCommand
        cmd.Connection = connect
         = "select logname from userinfo where logname=" + "'" + logname + "'"
        Dim result As String
        

        If DropDownList1.SelectedIndex <> 0 Then
            birthdayyear = DropDownList1.SelectedItem.Text
        End If
        If DropDownList2.SelectedIndex <> 0 Then
            birthdaymonth = DropDownList2.SelectedItem.Text
        End If
        If DropDownList3.SelectedIndex <> 0 Then
            birthdayday = DropDownList3.SelectedItem.Text
        End If
        birthday = birthdayyear + "/" + birthdaymonth + "/" + birthdayday

        Try
            connect.Open()
            result = cmd.ExecuteScalar
            If result = logname Then
                Response.Write("The logname is existed")
            Else
                = "insert into userinfo (logname,[password],username,gender,address,email,birthday) values ('" + logname + "','" + logpsw + "','" + username + "','" + gender + "','" + address + "','" + email + "','" + birthday + "')"
                cmd.ExecuteNonQuery()
                Response.Redirect("Registrationsuccessful.aspx?logname=" + logname)
            End If
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try
        connect.Close()

    End Sub
2010-12-01 23:19
kiska3088915
Rank: 2
等 级:论坛游民
帖 子:72
专家分:12
注 册:2009-11-7
得分:0 
我自己查了一下,好像是说要判定ispostback,但我不知道加哪,望大虾指教
2010-12-02 10:18
kiska3088915
Rank: 2
等 级:论坛游民
帖 子:72
专家分:12
注 册:2009-11-7
得分:0 
终于搞定了,在pageload里初始化赋值给dropdownlist前,先判定一下ispostback是否为false就行了
2010-12-02 10:28



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-327571-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.120196 second(s), 9 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved