Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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
NaniCh684
Comments
raghurocks at 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 at 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
0 OriginalGriff 474
1 Gihan Liyanage 338
2 ChauhanAjay 180
3 Sergey Alexandrovich Kryukov 163
4 Vinay Mistry 160
0 Sergey Alexandrovich Kryukov 9,011
1 OriginalGriff 7,941
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2014
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