コード例 #1
0
 private void GetMonths()
 {
     using (SqlCommand cmd = new SqlCommand("SELECT Month  FROM Acc_ProcessMonth where slno = (select isnull(max(slno),0) as nxt from acc_processmonth where active=1 and Processed =0)"))
     {
         cmd.CommandType = CommandType.Text;
         cmd.Connection  = con;
         using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
         {
             DataSet ds = new DataSet();
             sda.Fill(ds);
             DrpMonths.DataSource     = ds.Tables[0];
             DrpMonths.DataTextField  = "Month";
             DrpMonths.DataValueField = "Month";
             DrpMonths.DataBind();
             DrpMonths.Items.Insert(0, new ListItem("Select Month", "0"));
         }
     }
 }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string[] name = { "Select Name", "suresh", "Mukesh", "Ganesh", "Naresh" };

                DrpName.DataSource = name;
                DrpName.DataBind();

                ArrayList DatesList = new ArrayList();
                DatesList.Add("Select Date");
                for (int i = 1; i <= DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month); i++)
                {
                    DatesList.Add(i.ToString());
                    DrpDates.DataSource = DatesList;
                    DrpDates.DataBind();
                }

                string[] Mnames = DateTimeFormatInfo.CurrentInfo.MonthNames;
                DrpMonths.AppendDataBoundItems = true;   //By Default the AppendDataBoundItems of a dropdown list will be false
                DrpMonths.Items.Add("Select Month");
                DrpMonths.DataSource = Mnames;
                DrpMonths.DataBind();

                ArrayList YearsList = new ArrayList();
                YearsList.Add("Select year");
                for (int i = 1950; i <= DateTime.Now.Year; i++)
                {
                    YearsList.Add(i.ToString());
                    DrpYear.DataSource = YearsList;
                    DrpYear.DataBind();
                }

                string[] Wnames = DateTimeFormatInfo.CurrentInfo.DayNames;
                DrpDays.AppendDataBoundItems = true;     //By Default the AppendDataBoundItems of a dropdown list will be false
                DrpDays.Items.Add("Select Day");
                DrpDays.DataSource = Wnames;
                DrpDays.DataBind();
            }
        }