标签未在页面加载时拾取DropDownList值

时间:2013-11-19 14:34:22

标签: asp.net vb.net

此代码在我的页面加载中:

        If DDLSelectedYear.Items.Count = 0 Then
            For Each item As ListItem In selectedYear.Items
                DDLSelectedYear.Items.Add(item)
            Next
        End If
        If DDLSelectedYearEnd.Items.Count = 0 Then
            For Each item As ListItem In selectedYear.Items
                DDLSelectedYearEnd.Items.Add(item)
            Next
        End If

valYear = DDLSelectedYear.SelectedValue
labelSearchDate.Text = valYear

DropDownList值:

2013
2014
2015

标签值(预计会在初始页面加载时自动填充):

2013

页面加载时标签没有选中所选的值,任何想法如何使这项工作? 感谢

2 个答案:

答案 0 :(得分:1)

SelectedItemChanged事件中查看下拉列表,您会在那里看到正确的SelectedValue

答案 1 :(得分:0)

在填充DDL之前添加If Not Page.IsPostBack检查页面加载方法并添加@Karl Anderson提议的SelectedItemChanged事件处理程序