Home > ASP.Net > Bind Hours, Minutes and Seconds in ASP.net DropDownList

Bind Hours, Minutes and Seconds in ASP.net DropDownList


Hi all,

try this example to Bind Hours, Minutes and Seconds in ASP.net DropDownList

<div>
<fieldset style="width:330px;">
<legend>Populate Hour,Minute and Seconds in DropDownList</legend>Hours:
<asp:DropDownList ID="ddlHours" runat="server">
</asp:DropDownList>
Minutes:
<asp:DropDownList ID="ddlMinutes" runat="server">
</asp:DropDownList>
Seconds:
<asp:DropDownList ID="ddlSeconds" runat="server">
</asp:DropDownList>
</fieldset>
</div>

In Code behind :

 protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
PopulateHours();
PopulateMinutes();
PopulateSeconds();
}
}
private void PopulateHours()
{
for (int i = 0; i <= 24; i++)
{
ddlHours.Items.Add(i.ToString("D2"));
}
}
private void PopulateMinutes()
{
for (int i = 0; i < 60; i++)
{
ddlMinutes.Items.Add(i.ToString("D2"));
}
}
private void PopulateSeconds()
{
for (int i = 0; i < 60; i++)
{
ddlSeconds.Items.Add(i.ToString("D2"));
}
}

Hope this helps

Good Luck.

Advertisements
Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: