+ Reply to Thread
Results 1 to 3 of 3

Thread: How to do this CascadingDropDown?

  1. #1
    nsoni is offline VB.NET Forum Newbie nsoni is on a distinguished programming path ahead
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    Jan 2008
    Posts
    11
    Reputation
    34

    Default How to do this CascadingDropDown?

    Hello,
    I am trying to select Date OF Birth on a WEB FORM from three DropdownList control like YEAR MONTH and DAY respectively, I want that when i select month FEBRUARY then the DAY dropdownlist control should list the no .of day according to YEAR i mean if it is leap year bla bla bla.

    For this I m using AJAX cascading dropdown where i am not getteing response. The following are the code and webservices where DAY dropdown gets disabled becasue it doesnot get the value selected from YEAR or MONTH dropdown.
    Can anybody see this and let me know


    ''''''''''''''''''''''.aspx code
    HTML Code:
    <asp:DropDownList ID="ddlDOByear" runat="server" ></asp:DropDownList>
    <asp:DropDownList ID="ddlDOBmon" runat="server"></asp:DropDownList>
    <asp:DropDownList ID="ddlDOBday" runat="server"></asp:DropDownList>
                                
    <ajaxToolkit:CascadingDropDown id="CascadingDropDown1" runat="server" category="Year" prompttext="Year" ServiceMethod="GetDOBYears" ServicePath="WebService.asmx" TargetControlId="ddlDOByear" />
    
    <ajaxToolkit:CascadingDropDown id="CascadingDropDown2" runat="server" category="MONTH" prompttext="Month" ServiceMethod="GetDOBMonths" ServicePath="WebService.asmx" TargetControlId="ddlDOBmon" />
    
    <ajaxToolkit:CascadingDropDown id="CascadingDropDown3" runat="server" category="Day" LoadingText="Loading Days...." prompttext="Days" ServiceMethod="GetDOBDays" 
    ServicePath="WebService.asmx" TargetControlId="ddlDOBday" />

    '''''Web services code...............

    Code:
    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports System.Collections
    Imports System.Collections.Generic
    Imports System.Collections.Specialized
    Imports AjaxControlToolkit
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Configuration
    <System.Web.Script.Services.ScriptService()> _
    <WebService(Namespace:="http://nerdliness.com/")> _
    <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Public Class WebService
        Inherits System.Web.Services.WebService
        Public imon As Integer
    
        <WebMethod()> _
        Public Function GetDOBYears(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
            Dim i As New Long
            Dim txtyrs As String
            Dim mydobyear As New List(Of CascadingDropDownNameValue)
            For i = 1 To 90
                txtyrs = ""
                txtyrs = Year(Now()) - i
                mydobyear.Add(New CascadingDropDownNameValue(txtyrs, txtyrs))
            Next
            Return mydobyear.ToArray
        End Function
    
        <WebMethod()> _
            Public Function GetDOBMonths(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
            Dim txtmon As String
            Dim mydobmonth As New List(Of CascadingDropDownNameValue)
            For imon = 1 To 12
                txtmon = ""
                txtmon = MonthName(imon)
                mydobmonth.Add(New CascadingDropDownNameValue(txtmon, imon))
            Next
            Return mydobmonth.ToArray
        End Function
    
        <WebMethod()> _
            Public Function GetDOBDays(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
            Dim i As Long
            Dim txtdays As String
            Dim totday As Long
    
            Dim kvDays As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
    
            Dim intMonthid As Integer
            If Not kvDays.ContainsKey("MONTH") Or Not Int32.TryParse(kvDays("MONTH"), intMonthid) Then
                Return Nothing
            End If
            Dim mydobday As New List(Of CascadingDropDownNameValue)
    
            If intMonthid = 0 Then
                totday = 31
            Else
                totday = 30
            End If
            For i = 1 To totday
                txtdays = ""
                txtdays = i
                mydobday.Add(New CascadingDropDownNameValue(txtdays, txtdays))
            Next
            Return mydobday.ToArray
        End Function
    
    End Class

    When i RUN this project i can see that YEAR MONTH are doing fine but DAY remains disabled even if i change month from the list.

    Can u please ahve a look where is the problem.


    Thanx and Kind Regards
    nsoni

  2. #2
    blackdots is offline VB.NET Forum Newbie blackdots is on a distinguished programming path ahead
    .NET Framework
    .NET 2.0
    Join Date
    Nov 2009
    Age
    30
    Posts
    3
    Reputation
    0

    Default

    I have the same problem, some one tell me remove the loadingText in 1st Dropdownlist but it still doesn't word. Some body help me plz !

  3. #3
    blackdots is offline VB.NET Forum Newbie blackdots is on a distinguished programming path ahead
    .NET Framework
    .NET 2.0
    Join Date
    Nov 2009
    Age
    30
    Posts
    3
    Reputation
    0

    Default

    <aspropDownList id="ddlcities" runat="server"></asp:dropdownlist>
    <ajaxToolkit:CascadingDropDown id="cascadingdropdown1" runat="server" Category="name"
    LoadingText="[Đang tải...]" PromptText="[Chọn Tỉnh/Thành phố]" ServiceMethod="GetDropDownCities"
    ServicePath="services/commonServices.asmx" TargetControlID="ddlCities">
    </ajaxToolkit:CascadingDropDown>

    -------------------------------------------------------------------------

    <asp:dropdownlist id="ddlDistrict" runat="server" Enabled="True"></asp:dropdownlist>
    <ajaxToolkit:CascadingDropDown ID="cascadingdropdown2" runat="server" Category="name"
    LoadingText="[Đang tải...]" ParentControlID="ddlCities" PromptText="[Chọn Quận/Huyện]"
    ServicePath="services/commonServices.asmx" ServiceMethod="GetDropDownDistrict"
    TargetControlID="Dropdownlist1">
    </ajaxtoolkit:cascadingdropdown>


    ---------------------------------------------------------------

    [WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownCities(string knownCategoryValues, string category)
    {
    try
    {
    SqlConnection sqlConn = new SqlConnection(conStr);
    sqlConn.Open();
    SqlCommand sqlSelect = new SqlCommand("SELECT * FROM hanhchinh where parentid is null order by alias asc", sqlConn);
    sqlSelect.CommandType = System.Data.CommandType.Text;
    SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlSelect);
    DataSet myDataset = new DataSet();
    sqlAdapter.Fill(myDataset);
    sqlConn.Close();
    List<AjaxControlToolkit.CascadingDropDownNameValue > cascadingValues = new List<AjaxControlToolkit.CascadingDropDownNameValue >();
    foreach (DataRow dRow in myDataset.Tables[0].Rows)
    {
    string categoryID = dRow["id"].ToString();
    string categoryName = dRow["name"].ToString();
    cascadingValues.Add(new AjaxControlToolkit.CascadingDropDownNameValue(cate goryName, categoryID));
    }
    return cascadingValues.ToArray();
    }
    catch
    {
    throw new Exception("ko biet loi");
    }
    }


    ------------------------------------------------------------------------

    [WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownDistrict(string knownCategoryValues, string category)
    {
    int categoryID;
    StringDictionary categoryValues = AjaxControlToolkit.CascadingDropDown.ParseKnownCat egoryValuesString(knownCategoryValues);
    categoryID = Convert.ToInt32(categoryValues["id"]);
    SqlConnection sqlConn = new SqlConnection(conStr);
    sqlConn.Open();
    SqlCommand sqlSelect = new SqlCommand("SELECT * FROM hanhchinh where parentid = @categoryID", sqlConn);
    sqlSelect.CommandType = System.Data.CommandType.Text;
    sqlSelect.Parameters.Add("@categoryID", SqlDbType.Int).Value = categoryID;
    SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlSelect);
    DataSet myDataset = new DataSet();
    sqlAdapter.Fill(myDataset);
    sqlConn.Close();
    List<AjaxControlToolkit.CascadingDropDownNameValue > cascadingValues = new List<AjaxControlToolkit.CascadingDropDownNameValue >();
    foreach (DataRow dRow in myDataset.Tables[0].Rows)
    {
    string productID = dRow["id"].ToString();
    string productName = dRow["name"].ToString();
    cascadingValues.Add(new AjaxControlToolkit.CascadingDropDownNameValue(prod uctName, productID));
    }
    return cascadingValues.ToArray();
    }

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts