| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1272 人关注过本帖
标题:为什么取不到dropdownlist的值
只看楼主 加入收藏
kiska3088915
Rank: 2
等 级:论坛游民
帖 子:72
专家分:12
注 册:2009-11-7
结帖率:86.96%
收藏
已结贴  问题点数:16 回复次数:8 
为什么取不到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
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:16 
你设断点跟一下程序,告诉我DropDownList1.SelectedIndex和DropDownList1.SelectedItem.Text的值是什么?

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2010-12-01 21:47
kiska3088915
Rank: 2
等 级:论坛游民
帖 子:72
专家分:12
注 册:2009-11-7
收藏
得分:0 
回复 2楼 冰镇柠檬汁儿
报告头,看了一下,值都是“please choose”
2010-12-01 21:56
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:0 
值都知道了,还不明白问题出在什么地方了吗?

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2010-12-01 22:35
kiska3088915
Rank: 2
等 级:论坛游民
帖 子:72
专家分:12
注 册:2009-11-7
收藏
得分:0 
回复 4楼 冰镇柠檬汁儿
额,真不明白,问题是我调试时的确选择了出生年月啊,所以照理来说selectedindex不应该为0的,但是点submit的时候就是没把选中的数据读进去啊,我也不知道是怎么回事,求指教
2010-12-01 22:50
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:0 
submit按钮是.NET的控件吗?还是html的控件?能把submit响应的方法的代码发上来吗,让大家帮你看看

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2010-12-01 22:59
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
快速回复:为什么取不到dropdownlist的值
数据加载中...
 
   



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

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