2014年7月13日 星期日

[RESOLVED] how to get a list of year?


hi,


i would like to get a list of year and insert into a drop down list.


at least 10 years.


Private Sub BindListCtrlByYear(ByVal ctrlObject As Object)
Dim listCtrl As ListControl = CType(ctrlObject, DropDownList)
Dim year As String
Dim year2 As String


year = DateTime.Now.Year.ToString()
year2 = DateTime.Previous.Year.ToString()


listCtrl.Items.Clear()
listCtrl.Items.Add(New ListItem(year, "1"))
listCtrl.Items.Add(New ListItem(year2, "2"))



End Sub



Hi,


try to like this


 


For i As Integer = 1 To 15
listCtrl.Items.Add(new ListItem(i.ToString(), i.ToString()))
Next i

 



int iCurrentYear = DateTime.Now.Year;
for (int iCount = 0; iCount < 50; iCount++)
{
listBoxYear.Items.Add(new ListItem(Convert.ToString(iCurrentYear - iCount), Convert.ToString(iCount + 1)));
}



Private Sub BindListCtrlByYear(ByVal ctrlObject As Object)
Dim listCtrl As ListControl = CType(ctrlObject, DropDownList)
Dim year As Date = DateTime.Now
For intcnt As Integer = 0 To 10
listCtrl.Items.Add(New ListItem(year.Year, year & intcnt + 1))
year = year.AddYears(-1)
Next
End Sub



For i as Integer = Now.Year to Now.Year + 10... Ddl.items.add(i)...

thank you so much.


it works and solved.Laughing


have a nice day.



Hi,


Since you have solved your problem, please mark it as an answer.


If you have any other problem, welcome to post it in the asp.net forums.


Best Regards,

Amy Peng 


沒有留言:

張貼留言