Simply Show the Consequent Year like 2010-2011 in DropdownList Using C# Coding
Here I explained about how to show or bind Consequent Year like 2010-2011 in DropdownList Using C# Coding. Normally our DropdownList binding only year like 1900,1901..etc. here using for loop just Consequent year between hypen(-). How to show the Consequent Year like 2010-2011 in DropdownList Using C# Coding
Binding year normal List:
Find the code for Simply Show the Consequent Year like 2010-2011 in DropdownList Using C# Coding.
int year = Convert.ToInt32(DateTime.Now.Year.ToString());
string data = string.Empty;
for (int AD = 1900; AD <= year; AD++)
{
//normal year binding....
data = Convert.ToInt32(AD + 1).ToString();
DropDownList1.Items.Add(data);
}Binding Consequent Year like 2010-2011 in DropdownList:
int year = Convert.ToInt32(DateTime.Now.Year.ToString());
string data = string.Empty;
for (int AD = 1900; AD <= year; AD++)
{
//Consequent Year binding Like 2010-2011 ..etc
data = AD + " - " + (AD + 1);
DropDownList1.Items.Add(data);
}Sample Coding
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//DropDownList
int year = Convert.ToInt32(DateTime.Now.Year.ToString());
string data = string.Empty;
for (int AD = 1900; AD <= year; AD++)
{
//data = AD + " - " + (AD + 1);
data = Convert.ToInt32(AD + 1).ToString();
DropDownList1.Items.Add(data);
}
}
}Conclusion:
simply Show the Consequent Year coding will useful to all...