Asp.net如果下拉菜单中有此项,则按钮将被禁用 [英] Asp.net if dropdown has this item a button will be disabled

查看:83
本文介绍了Asp.net如果下拉菜单中有此项,则按钮将被禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,程序员在这里遇到了问题.香港专业教育学院创建的集合,以便我可以在数据库上获取所有日期,到目前为止,它的工作会导致我使用断点获取价值(2010、2011、2012、2013).现在我的下拉列表项包括(2010,2011,2012,2013,2014).基本上,因为数据库具有与下拉菜单相同的值2010-2013,所以我希望禁用按钮,并且在下拉菜单的2014年将启用该按钮.有帮助吗?
我的代码:

Hello programmers, got a problem here. Ive created collection so that i can get all the dates on my database and so far it works cause im getting value using breakpoints (2010,2011,2012,2013). Now my dropdown items consist of (2010,2011,2012,2013,2014). Basically since the database has this value 2010-2013 in the same as dropdown i want a button to be disabled and on 2014 of the dropdown the button will be enabled. Any help?
My Code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If IsPostBack = False Then
            BindYear()
            CategoryBindGrid()
            Dim coursecatyrTp As New CourseCatYear
            _coursecatyearDAL = New CourseCatYearDAL
            Dim coursecatyrCol As New CourseCatYearCollection
            coursecatyrTp.Year = drpdwnYear.Text
            coursecatyrCol = _coursecatyearDAL.SelectByYear()

            Dim j As String
            For i As Integer = 0 To coursecatyrCol.Count - 1
                j = coursecatyrCol.Item(i).Year
                If j.CompareTo(drpdwnYear.Text) Then
                    bntCreateYear.Enabled = False
                Else
                    bntCreateYear.Enabled = True
                End If
            Next
        End If
    End Sub
    Private Sub BindYear()
        Dim lastYear, currentYear As Integer
        currentYear = DateTime.Today.Year
        lastYear = currentYear - 1
        For yr As Integer = lastYear To currentYear + 3
            drpdwnYear.Items.Add(yr)
        Next

        If drpdwnYear.Items Is Nothing Then
        Else
            drpdwnYear.Text = currentYear
        End If
    End Sub





Public Function SelectByYear() As CourseCatYearCollection
       Try

           Dim sqlConn As New SqlConnection(_connString)
           sqlConn.Open()

           Dim sqlCmd As New SqlCommand("Select Distinct Year from [CourseCatYear]", sqlConn)
           Dim dr As SqlDataReader = sqlCmd.ExecuteReader()
           Dim coursecatyearColl As New CourseCatYearCollection
           Dim coursecatyearTP As CourseCatYear = Nothing

           While dr.Read()
               'Create User object
               coursecatyearTP = New CourseCatYear
               coursecatyearTP.Year = dr("Year").ToString
               coursecatyearColl.Add(coursecatyearTP)
           End While
           dr.Close()

           Return coursecatyearColl
       Finally
           If _sqlConn IsNot Nothing Then
               If _sqlConn.State = Data.ConnectionState.Open Then
                   _sqlConn.Close()
               End If
           End If
       End Try
       Return Nothing
   End Function


Public Class CourseCatYearCollection
    Inherits CollectionBase

    Public Sub Add(ByVal item As CourseCatYear)
        List.Add(item)
    End Sub

    Public Sub Remove(ByVal item As CourseCatYear)
        List.Remove(item)
    End Sub

    Default Public Property Item(ByVal index As Integer) As CourseCatYear
        Get
            Return DirectCast(List(index), CourseCatYear)
        End Get
        Set(ByVal value As CourseCatYear)
            List(index) = value
        End Set
    End Property
End Class

推荐答案

您可以检查是否满足此条件..
在DropDownList1_SelectedIndexChanged事件中..
You can check in if condition for this..
inside the DropDownList1_SelectedIndexChanged event..
if(DropDownList1.SelectedItem.Text == '2014')
{
    btnYear.enable = true;
}
else
{
    btnYear.enable = false;
}


这篇关于Asp.net如果下拉菜单中有此项,则按钮将被禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆