DropDownList

  • Thread starter Thread starter niju
  • Start date Start date
N

niju

Hi
I have a dropdownlist which consists of numeric values that represent
5-minute intervals which are displayed in ascending order
i.e. 00
05
10
15
20
25
30
35
40
45
50
55

When the page is loaded, a default value is selected based on the
current time. However, when this default value is selected, it alters
the order of all the other values on the dropdownlist, and the default
value itself becomes the first value in the dropdownlist.
e.g. 25
30
35
40
45
50
55
00
05
10
15
20
How do I keep the exact order of these values?
 
Thanks Eliyah
my code is working fine. I just want the dropdownlist to populate value
in ascending order.

Niju
 
Here is the code

private void getMinute()
{
DateTime dateTime = DateTime.Now;
string strHourMin,lstItem,strMin =null;

string[] values;
char[]delimiters = {':',' '};

strHourMin = dateTime.ToString("t");
values = strHourMin.Split(delimiters);

int minute = System.Convert.ToInt32(values[1]);
int tempMinute = 0;
string strTempMin = null;




string strRightDigit = values[1].Substring(1,1);
string strLeftDigit = values[1].Substring(0,1);

int intRightDigit = System.Convert.ToInt32(strRightDigit);
int intLeftDigit = System.Convert.ToInt32(strLeftDigit);

if (intRightDigit <5)
{
strTempMin = intLeftDigit.ToString() + "5";
}
else
{
tempMinute = intLeftDigit + 1;
strTempMin = tempMinute.ToString() + "0";
}
int intMinute = System.Convert.ToInt32(strTempMin);
strMin = intMinute.ToString("00");

for (int i =0;i<11;i++)
{
intMinute = (intMinute + 5);
if (intMinute > 55)
{intMinute =0;}
lstItem = intMinute.ToString("00");

sltMinute.Items.Insert(i,new ListItem(lstItem));

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top