i am using combo box as the input for the birthdate for my program. i had using the related combobox as my reference for my work. i have 3 combobox, that is year, month and day. It look alright when i have select the year and loop for the month. But i face a problem, i can't get the selected value for the year combo box when i wan to loop for the days. This lead me cannot get the value for day espeacially in february. Its can't count on the leap year. if i am using the postback, these doesn't happend. below is my code:
aspx:
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="radComboBoxWMDY.aspx.cs" Inherits="radComboBoxWMDY" %>
<%
@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head runat="server">
<title></title>
</
head>
<
body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
Year:
<telerik:RadComboBox ID="rcbYear" runat="server" onselectedindexchanged="rcbYear_SelectedIndexChanged"
OnClientSelectedIndexChanging="LoadMonth" onitemsrequested="rcbYear_ItemsRequested"> </telerik:RadComboBox>
Month:
<telerik:RadComboBox ID="rcbMonth" runat="server" onselectedindexchanged="rcbMonth_SelectedIndexChanged" OnClientSelectedIndexChanging="LoadDay" OnClientItemsRequested="ItemsLoaded" onitemsrequested="rcbMonth_ItemsRequested">
</telerik:RadComboBox>
Day:
<telerik:RadComboBox ID="rcbDay" runat="server" OnClientItemsRequested="ItemsLoaded" onitemsrequested="rcbDay_ItemsRequested" onselectedindexchanged="rcbDay_SelectedIndexChanged" >
</telerik:RadComboBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
<script type="text/javascript">
//global variables for the countries and cities comboboxes
var
rcbMonth;
var rcbDay;
var rcbYear;
function pageLoad()
{
// initialize the global variables
// in this event all client objects
// are already created and initialized
rcbMonth = $find(
"<%= rcbMonth.ClientID %>");
rcbDay = $find(
"<%= rcbDay.ClientID %>");
rcbYear = $find(
"<%= rcbYear.ClientID %>");
}
function
LoadMonth(combo, eventArqs)
{
var item = eventArqs.get_item();
rcbMonth.set_text(
"Loading...");
rcbDay.clearSelection();
// if a continent is selected
if (item.get_index() > 0)
{
// this will fire the ItemsRequested event of the
// countries combobox passing the continentID as a parameter
rcbMonth.requestItems(item.get_value(),
false);
}
else
{
// the -Select a continent- item was chosen
rcbMonth.set_text(
" ");
rcbMonth.clearItems();
rcbDay.set_text(
" ");
rcbDay.clearItems();
}
}
function
LoadDay(combo, eventArqs)
{
var item = eventArqs.get_item();
//rcbDate.set_text("Loading...");
// this will fire the ItemsRequested event of the
// cities combobox passing the countryID as a parameter
rcbDay.requestItems(item.get_value(),
false);
}
function
ItemsLoaded(combo, eventArqs)
{
if (combo.get_items().get_count() > 0)
{
// pre-select the first item
combo.set_text(combo.get_items().getItem(0).get_text());
combo.get_items().getItem(0).highlight();
}
//combo.showDropDown();
}
</script>
</
body>
</
html>
the code behind:
using
System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
usingTelerik.Web.UI;
public
partial class radComboBoxWMDY : System.Web.UI.Page
{
DateTime tnow = DateTime.Now;
int year, month,i , day;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
LoadYear();
}
}
private bool CheckLeap(int year)
{
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
return true;
else return false;
}
//binding every month day
private void BindDays(int year, int month)
{
int i;
ArrayList AlDay = new ArrayList();
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
for (i = 1; i <= 31; i++)
AlDay.Add(i);
break;
case 2:
if (CheckLeap(year))
{
for (i = 1; i <= 29; i++)
AlDay.Add(i);
}
else
{
for (i = 1; i <= 28; i++)
AlDay.Add(i);
}
break;
case 4:
case 6:
case 9:
case 11:
for (i = 1; i <= 30; i++)
AlDay.Add(i);
break;
}
rcbDay.DataSource = AlDay;
rcbDay.DataBind();
}
protected void LoadYear()
{
ArrayList AlYear = new ArrayList();
for (i = 2002; i <= 2010; i++)
AlYear.Add(i);
rcbYear.DataSource = AlYear;
rcbYear.DataBind();
}
protected void LoadMonth(int year)
{
ArrayList AlMonth = new ArrayList();
for (i = 1; i <= 12; i++)
AlMonth.Add(i);
rcbMonth.DataSource = AlMonth;
rcbMonth.DataBind();
}
protected void rcbYear_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
{
year =
Int32.Parse(rcbYear.SelectedValue);
//month = Int32.Parse(rcbMonth.SelectedValue);
//BindDays(year, month);
}
protected void rcbMonth_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
{
year =
Int32.Parse(rcbYear.SelectedValue);
month =
Int32.Parse(rcbMonth.SelectedValue);
//BindDays(year, month);
}
protected void rcbYear_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
{
LoadYear();
}
protected void rcbMonth_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
{
LoadMonth(
Int32.Parse(e.Text));
}
protected void rcbDay_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
{
BindDays(year,
Int32.Parse(e.Text));
}
protected void Button1_Click(object sender, EventArgs e)
{
string s = string.Format("{0}, {1}, {2}", year, month, day);
Label1.Text = s;
}
protected void rcbDay_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
{
day =
Int32.Parse(rcbDay.SelectedValue);
}
}
hope i can get the respond from u all faster!!!thank you!!!
best regards:
sk