Click here to Skip to main content
12,253,139 members (50,128 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET C#4.0
hi
i want code for how to bind 24 hrs time (hrs only) in dropdown list. how can i do.
please help me




Thanks in advance..
Posted 29-Nov-12 0:52am
NaniCh743
Comments
raghurocks 29-Nov-12 7:18am
   
then u can use for loop...like the below...put this code in page_load event...hope this helps


if (!Page.IsPostBack)
{
for (int i = 0; i < 24; i++)
{
ddlhrs.Items.Add((i + 1).ToString());
}
}
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

then u can use for loop...like the below...put this code in page_load event...hope this helps

if (!Page.IsPostBack)
{
for (int i = 0; i < 24; i++)
{
ddlhrs.Items.Add((i + 1).ToString());
}
}
  Permalink  
v2
Comments
NaniCh 30-Nov-12 1:03am
   
Thanks for your supporting..
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

protected void Page_Load(object sender, EventArgs e)
   {
       if(!IsPostBack)
       {
           BindHours();
       }
   }
  private void BindHours()
   {
       ddlHours.Items.Insert(0, new ListItem("Select Hour", "0"));
       for (int i = 1; i <= 24; i++)
       {
           ddlHours.Items.Insert(i, new ListItem(i.ToString(), i.ToString()));
       }
 
   }
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

string ktr;
        for (int k = 0; k < 24; k++)
        {
           if (k < 10)
           {
              ktr = "0" + k.ToString();
           }
           else
           {
              ktr = k.ToString();
           }
         ddltime.Items.Add(new ListItem(ktr + ":" + "00"));
        }
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160426.1 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100