Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
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());
}
}

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

C#
if (!Page.IsPostBack)
{
for (int i = 0; i < 24; i++)
{
ddlhrs.Items.Add((i + 1).ToString());
}
}
 
Share this answer
 
v2
Comments
NaniCh 30-Nov-12 1:03am    
Thanks for your supporting..
C#
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()));
       }

   }
 
Share this answer
 
C#
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"));
        }
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900