Here is an example how we can generate years in dropdownlist in asp.net at runtime
Add a drop downlist to your page with id DropDownList1
Here is method which will populate dropdownlist
//code
protected void year()
{
for (int i = DateTime.Now.Year; i >= 2000; i--)
{
ListItem obj = new ListItem();
obj.Text = i.ToString();
obj.Value = i.ToString();
DropDownList1.Items.Add(obj);
}
}
call year() method in page load event (.cs)
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
year();
}
Show Years in dropDownList
Category:
DropDownList,
ListItem,
show year in dropdownlist
Subscribe to:
Post Comments (Atom)
Hi ,
I want to display date in DropDownList and the date is like 2000-2001,2001-2002,2002-2003 etc.
And user select any from it and will display in text box.
Thanks.
you can use the following code
for (int i = DateTime.Now.Year; i >= 2000; i--)
{
ListItem obj = new ListItem();
obj.Text=i.ToString()+"-"+(i+1).ToString();
obj.Value=i.ToString()+"-" +(i + 1).ToString();
DropDownList1.Items.Add(obj);
}
and use the selectedindexchaged event to display selected value in text box
Hi Dear,
I want to genearte date in following format and use it in code.
e.g.1011FRP10001
where 1011 is year 2010-2011
FRP is the hard coded string
1 is my dept number
0001 is record number
Could you suggest how 1011FRP10001 will be acheived in asp.net?
gud work ..... kwwp it up
Hi, I am from Bangladesh. I am a web developer. I have searched many sites but I haven't found anywhere what I was looking for except this blog. Very useful code and helpful guidelines in short. Please keep up the good work.