Click here to Skip to main content
14,980,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am totally confused...which are first fired in aspx page code behind events or html controls?..i have an user control in that i used cascading drop down for states,districts and areas...how to load cascading drop down in user control page load....cascading Drop down code is
ASP.NET
<tr>
    <td class="caption">
        State:
        <asp:DropDownList ID="ddlCState" runat="server" CssClass="userentry">
        </asp:DropDownList>
        <cc1:CascadingDropDown ID="cdlCStates" TargetControlID="ddlCState" PromptText="Select State"
            ServicePath="~/CasCadingDropDown.asmx" ServiceMethod="GetStates"  runat="server"
            Category="StateId" LoadingText="Loading..." />
    </td>
</tr>
<tr>
    <td class="caption">
        District:
        <asp:DropDownList ID="ddlCDistrict" runat="server" CssClass="userentry">
        </asp:DropDownList>
        <cc1:CascadingDropDown ID="cdlCDistrict" TargetControlID="ddlCDistrict" PromptText="Select District"
            ServicePath="~/CasCadingDropDown.asmx" ServiceMethod="GetDistricts"  runat="server"
            Category="DistrictId" ParentControlID="ddlCState" LoadingText="Loading..." />
    </td>
</tr>
<tr>
    <td class="caption">
        Area:
        <asp:DropDownList ID="ddlCArea" runat="server" CssClass="userentry">
        </asp:DropDownList>
        <cc1:CascadingDropDown ID="cdlCAreas" TargetControlID="ddlCArea" PromptText="Select Area"
            ServicePath="~/CasCadingDropDown.asmx" ServiceMethod="GetAreas"  runat="server"
            Category="AreaId" ParentControlID="ddlCDistrict" LoadingText="Loading..." />
    </td>
</tr>

Web Service code is

C#
[WebMethod]
[System.Web.Script.Services.ScriptMethod]
public CascadingDropDownNameValue[] GetStates(string knownCategoryValues)
{
    string query = "SELECT statename, stateid FROM tblstates";
    List<cascadingdropdownnamevalue> states = GetData(query);
    return states.ToArray();
}

[WebMethod]
[System.Web.Script.Services.ScriptMethod]
public CascadingDropDownNameValue[] GetDistricts(string knownCategoryValues)
{
    int state = Formats.ConvertToInt(CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)["StateId"]);
    string query = string.Format("select districtname,districtid from tbldistricts where stateid={0}", state);
    List<cascadingdropdownnamevalue> districts = GetData(query);
    return districts.ToArray();
}
[WebMethod]
[System.Web.Script.Services.ScriptMethod]
public CascadingDropDownNameValue[] GetAreas(string knownCategoryValues)
{
    int district = Formats.ConvertToInt(CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)["DistrictId"]);
    string query = string.Format("select areaname,areaid from tblareamst where district={0}", district);
    List<cascadingdropdownnamevalue> areas = GetData(query);
    return areas.ToArray();
}
[WebMethod]
[System.Web.Script.Services.ScriptMethod]
public CascadingDropDownNameValue[] GetPincode(string knownCategoryValues)
{
    int area = Formats.ConvertToInt(CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)["AreaId"]);
    string query = string.Format("select pincode from tblareamst where areaid={0}", area);
    List<cascadingdropdownnamevalue> Pincode = GetData(query);
    return Pincode.ToArray();
}
private List<cascadingdropdownnamevalue> GetData(string query)
{

    string connstring = String.Format("Server=192.168.1.100;Port=5432;Encoding=UNICODE;User Id=postgres;Password=sggkishore;Database=SNCF;");
    NpgsqlCommand cmd = new NpgsqlCommand(query);
    List<cascadingdropdownnamevalue> values = new List<cascadingdropdownnamevalue>();
    using (NpgsqlConnection conn = new NpgsqlConnection(connstring))
    {
        conn.Open();
        cmd.Connection = conn;
        using (NpgsqlDataReader reader = cmd.ExecuteReader())
        {
            while (reader.Read())
            {
                values.Add(new CascadingDropDownNameValue
                {
                    name = reader[0].ToString(),
                    value = reader[1].ToString()
                });
            }
            reader.Close();
            conn.Close();
            return values;
        }
    }
}
Posted
Updated 6-Oct-15 20:11pm
v3
Comments
[no name] 7-Oct-15 2:27am
   
Where is the issue now. When page will first time then you need to bind data to state dropdown. Then on change of state dropdown it will load value to district dropdown as per state dropdown value..
User-11630313 7-Oct-15 2:41am
   
at the time of data retrieval the states are not loading...cascading drop down not loading in page load event

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900