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
if(DropDownList1.SelectedItem.Text == '2014') { btnYear.enable = true; } else { btnYear.enable = false; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)