Click here to Skip to main content
15,907,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
VB
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


VB
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

VB
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
Posted
Updated 11-Oct-11 22:26pm
v2

1 solution

You can check in if condition for this..
inside the DropDownList1_SelectedIndexChanged event..
C#
if(DropDownList1.SelectedItem.Text == '2014')
{
    btnYear.enable = true;
}
else
{
    btnYear.enable = false;
}
 
Share this answer
 
Comments
hitech_s 12-Oct-11 4:52am    
My 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900