Friday 27 September 2013

Fill dropdownlist using Cashcading style sheet in asp.net

HTML-- without parent id

<asp:DropDownList ID="ddl_block" runat="server"  >  </asp:DropDownList>

<asp:CascadingDropDown ID="Cascadingddl_block" runat="server" Category="SubDistrict" TargetControlID="ddl_block" LoadingText="Loading SubDistrict..." PromptText="---Select---" ServiceMethod="BindSubDitstrictdropdown" ServicePath="~/DropdownWebService.asmx"> </asp:CascadingDropDown>

WebService-

 [WebMethod(EnableSession = true)]
    public CascadingDropDownNameValue[] BindStatedropdown(string knownCategoryValues, string category)
    {

        StringDictionary countrydetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        DataTable dtSelectMethod = new DataTable();
        dtSelectMethod = Select_All_Data("mstAState", "*", "Active='1'", "StateName", "ASC");
        int Index = 0;
        List<CascadingDropDownNameValue> statedetails = new List<CascadingDropDownNameValue>();
        foreach (DataRow dtstaterow in dtSelectMethod.Rows)
        {
            string StateCode = dtstaterow["StateCode"].ToString();
            string StateName = dtstaterow["StateName"].ToString();
            statedetails.Add(new CascadingDropDownNameValue(StateName, StateCode));
        }
        return statedetails.ToArray();
    }                    


HTML-- with parent id

<asp:DropDownList ID="ddl_block" runat="server" ></asp:DropDownList>

<asp:CascadingDropDown ID="Cascadingddl_block" runat="server" Category="SubDistrict" TargetControlID="ddl_block" LoadingText="Loading SubDistrict..." PromptText="---Select---" ServiceMethod="BindSubDitstrictdropdown" ServicePath="~/DropdownWebService.asmx"   ParentControlID="ddl_district"> </asp:CascadingDropDown>


[WebMethod(EnableSession = true)]
    public CascadingDropDownNameValue[] BindClusterdropdown(string knownCategoryValues, string category)
    {
        string StateCode;
        StringDictionary StateCodedetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        StateCode = Convert.ToString(StateCodedetails["State"]);
        
        string clusternames = null;
        string clus = Session["clustercheck"].ToString();
        if (clus != "")
        {
            if (clus.Length == 6)
            {
                clusternames = "'" + clus + "'";
            }
            else
            {
                // clusternames = clus.Substring(0, clus.Length - 1);
                clusternames = clus;
            }
        }

        DataTable dtSelectMethod = new DataTable();
        string condition = "";
        if (clusternames == null)
        { condition = "StateCode='" + StateCode + "'"; }
        else { condition = " StateCode='" + StateCode + "' and ClusterCode in (" + clusternames + ") "; }
         
       // string 
        dtSelectMethod = Select_All_Data("mstBCluster", "*", condition, "ClusterName", "ASC");

        List<CascadingDropDownNameValue> regiondetails = new List<CascadingDropDownNameValue>();
        foreach (DataRow dtregionrow in dtSelectMethod.Rows)
        {
            string ClusterCode = dtregionrow["ClusterCode"].ToString();
            string ClusterName = dtregionrow["ClusterName"].ToString();
            regiondetails.Add(new CascadingDropDownNameValue(ClusterName, ClusterCode));

        }
        return regiondetails.ToArray();
    }

             

No comments:

Post a Comment

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...