Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Automatic binding of Days, Months, Years to a dropdown list control,How to fill dropdownlist with days, month and year

here you can bind threee dates , today date and tomrrow date, and day after tomorrow dates to drop down list.

here we have to use namespace   usingSystem.Globalization;

.aspx page code :

<table width="300" border="0" cellspacing="1" cellpadding="7">
  <tr>
                                <td>
                                    <asp:DropDownList ID="DdlDATE"runat="server"Height="23px"Width="233px"AutoPostBack="True">
                                        <asp:ListItem Selected="True"Value="0">--Select Date--</asp:ListItem>
                                    </asp:DropDownList>
                                </td>
                            </tr>

</table>

.cs page code

  protected void Page_Load(objectsender, EventArgs e)
        {
            if(!IsPostBack)
            {
            ListItem lt = new ListItem();
            lt.Text = "--Select Date--";
            lt.Value = "0";
            DdlDATE.Items.Add(lt);          
            StringsDate = DateTime.UtcNow.ToString();
            DateTimedatevalue = (Convert.ToDateTime(sDate.ToString()));  
            stringpattern =            CultureInfo.CurrentCulture.DateTimeFormat.MonthDayPattern;
            pattern = pattern.Replace("MMMM", "MMM");
            stringformatted = "Today, " + datevalue.ToString(pattern);
            stringformatted1 = "Tomorrow, " + datevalue.AddDays(1).ToString(pattern);
            stringformatted2 = datevalue.AddDays(2).ToString(pattern);
            DdlDATE.Items.Add(formatted);
            DdlDATE.Items.Add(formatted1);
            DdlDATE.Items.Add(formatted2);
            }

        }


This post first appeared on Asp.netSourceCodes, please read the originial post: here

Share the post

Automatic binding of Days, Months, Years to a dropdown list control,How to fill dropdownlist with days, month and year

×

Subscribe to Asp.netsourcecodes

Get updates delivered right to your inbox!

Thank you for your subscription

×