开发者

VB asp.net set result of a control to a variable

trying to set the result of dropdownlist to a variable but having great troubles.

    Sub OutageSource(ByVal sender As Object, ByVal e As EventArgs) Handles Year.SelectedIndexChanged
    Dim year As Integer


    year = year.SelectedValue

    MsgBox(year)

    End Sub

     <asp:DropDownList ID="Year" runat="server" onChange = "" Width="70px">
                    <asp:ListItem Value=1988>1988</asp:ListItem><asp:ListItem Value=1987>1987</asp:ListItem>
                </asp:DropDownList>

So im trying to get year var in the vb section equal to the selected year in the page. Im used to VBA so perhaps 开发者_如何转开发theres something im missing?

Cheers ty


I just copied your code into a VS2008 demo, and it seems that VB.NET's case (de)sensitivity is the problem (at least in my case - no pun intended). VB.NET doesn't see a difference in the year variable, and the Year variable, and assumes the former since you declared it locally to the Sub.

Try calling the local variable intYear and see what happens


Your year variable has the same name as the control.
You can either change the name or write Me.Year to refer to the control.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜