reagan123 Posted October 10, 2005 Posted October 10, 2005 ok.. i have a drop down list that is populated by the following code // Set the exp year drop down list values. int currentYear = DateTime.Now.Year; int finalYear = currentYear + 5; ddlExpYear.Items.Add(new ListItem("", "")); for(int i=currentYear; i<finalYear; i++) ddlExpYear.Items.Add(new ListItem(i.ToString(), i.ToString())); works fine but it gives me the values 2005-2010 How can I tweak this to get it to show 05-10. I basically need to get a month value out of one ddl and then the year value in the other ddl and be able to assign them to an int in like this '1206'. Any suggestions? Thanks Quote
*Experts* Nerseus Posted October 10, 2005 *Experts* Posted October 10, 2005 Assuming your years are always > 2000, just subtract 2000: // Set the exp year drop down list values. int currentYear = DateTime.Now.Year - 2000; int finalYear = (currentYear + 6); for(int i=currentYear; i<finalYear; i++) Debug.WriteLine(i.ToString("00")); Have you considered storing the full year in the dropdown and just converting to a 2 digit year when they pull the value out? -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
reagan123 Posted October 10, 2005 Author Posted October 10, 2005 nope.. hadn't thought about changing it after the value is selected... i think the -2000 should work, but if you feel like it, could you post an example for after the selection? ***EDIT hmm.. subtracting 2000 seems to give me the following 5,6,7,8,9 I'm trying to get 05,06,07 etc.. man I can't wait till i get better at this stuff :) Quote
*Experts* Nerseus Posted October 10, 2005 *Experts* Posted October 10, 2005 Note the "00" on the ToString() method call - it will pad the number. You can add the year value as a 4 digit year (as a string). When you pull out the string ("2002" for example), which you know is a number, you can then convert it to a 2 digit year however you want. You might still want to subtract 2000 - or some other "smarter" function, if needed. -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
reagan123 Posted October 10, 2005 Author Posted October 10, 2005 i think i got it.. i'll test it out tomorrow.. thanks for the clarification and suggestions Quote
reagan123 Posted October 11, 2005 Author Posted October 11, 2005 man.. still having problems.. .here's the overall picture. I have to drop down lists ddlMonth and ddlYear. ddlMonth is populated like this. <asp:ListItem Value="1">01</asp:ListItem> <asp:ListItem Value="2">02</asp:ListItem> <asp:ListItem Value="3">03</asp:ListItem> ... <asp:ListItem Value="12">12</asp:ListItem> the ddlYear is populated like this. // Set the exp year drop down list values. int currentYear = DateTime.Now.Year - 2000; int finalYear = currentYear + 6; ddlExpYear.Items.Add(new ListItem("", "")); for(int i=currentYear; i<finalYear; i++) ddlExpYear.Items.Add(new ListItem(i.ToString("00"), i.ToString("00"))); What I'm trying to do is to get an int variable that ends up in this format '0205'... I can't seem to do it... I get '205' string month = ddlExpMonth.SelectedValue.Trim(); string year = ddlExpYear.SelectedValue.Trim(); int ExpDate = Int32.Parse(month+year); Please help if possible. Quote
Administrators PlausiblyDamp Posted October 11, 2005 Administrators Posted October 11, 2005 Integers do not contain formatting 205 is numerically the same as 0205 (as is 00000000000000000000205) the leading 0s have no meaning. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
reagan123 Posted October 11, 2005 Author Posted October 11, 2005 ok.. but i need to send an integer value to an api... it's expecting the format to be a four digit integer such as '0105' or '0607' or whatever... how do i get it in that format? any suggestions? Quote
Administrators PlausiblyDamp Posted October 11, 2005 Administrators Posted October 11, 2005 If it expects an integer as 0105 then either it will accept 105 or it is not expecting an integer. Are you sure it isn't requesting a string that contains an integer? If possible could you post the API declaration here. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
reagan123 Posted October 11, 2005 Author Posted October 11, 2005 sure.. when i sent 105 i got an error.. this is cut and pasted from the integration guide.. .thanks so much for your patience and help EXPDATE -- Expiration date of the credit card in mmyy format. For example, 0308 represents March 2008. Required=Yes Type=Numeric MaxLength=4 Quote
Leaders snarfblam Posted October 12, 2005 Leaders Posted October 12, 2005 Just a quick side note: I recommend using (Year) Mod 100 instead of (Year) - 2000 to get the last two digits of a year... otherwise, 1998 - 2000 will return a year of -2 instead of 98. I guess this would be Nerseus' "smarter" function. Quote [sIGPIC]e[/sIGPIC]
*Experts* Nerseus Posted October 12, 2005 *Experts* Posted October 12, 2005 The "smarter" function I was thinking of is the one used by SQL Server, which is usually a 50/50 split or, more commonly, 80/20. Meaning, 80-99 is 1900 + value, values 00-79 are 2000 + value. In the case of an expiration date, I think you can safely assume that every value is 2000+, that's why I wouldn't currently worry about 1900-1999 dates - meaning, subtract 2000 and you should be fine until 3000. I agree with Plausibly, let's see that API declaration to help further. I would bet that the API wants a string. In that case, simply use something like: string expiration = ddlExpMonth.SelectedValue.Trim() + ddlExpYear.SelectedValue.Trim(); That assumes you're storing a 2 digit month and year in each dropdown. Otherwise, get the month and year as an int and use something like the following to piece it together: int month = 11; // get real value from dropdown int year = 2008; // get real value from dropdown string expiration = month.ToString("00") + (year - 2000).ToString("00"); -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
reagan123 Posted October 12, 2005 Author Posted October 12, 2005 i'll try to pass it as a string as suggested above... i'll be back with the results :) thanks so much for all of the help. Quote
reagan123 Posted October 12, 2005 Author Posted October 12, 2005 passed it as a string and it worked.. thanks so much. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.