Dropdownlist with formating [Resolved]

Posted by Anweshabhowmick under Regular Expressions on 2/23/2011 | Points: 10 | Views : 1416 | Status : [Member] | Replies : 3
I have a dropdownlist1 and i want the year from 190 to till date
the main problem is that How can i format my Dropdownlist1 by------
1990-1991
1991-1992
.
.
.
2010-2011

like this.

Can anyone help me out.
Dropdownlist with that type value.

int j = Convert.ToInt32(DateTime.Now.Year.ToString());
for (int i = 1990; i <= j; i++)
{
DropDownList1.Items.Add(i.ToString());
}




Responses

Posted by: SheoNarayan on: 2/23/2011 [Administrator] HonoraryPlatinum | Points: 50

Up
0
Down

Resolved
Dear Anweshabhowmick,

You were almost there, it is just a simple logic. I modified your code a bit and I am getting the desired result.

 int j = Convert.ToInt32(DateTime.Now.Year.ToString());

string data = string.Empty;
for (int i = 1990; i <= j; i++)
{
data = i + " - " + (i + 1);
drop1.Items.Add(data);
}


Hope this helps

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Anweshabhowmick, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Anweshabhowmick on: 2/23/2011 [Member] Starter | Points: 25

Up
0
Down
Thank u so much Sheo.............it is the answer i m looking for.


Anweshabhowmick, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naimishforu on: 2/23/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Wow Sheo, thanks for the same.

Thanks,
Naimish
http://dotnetinterview.zxq.net/
http://naimishpandya.blogspot.in/

Anweshabhowmick, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response