Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Method error 500

$
0
0

I'm using cascading drop down where parent drop down is populating right but child drop down is giving "method error 500"

HTML 

<asp:DropDownList ID="ddlCountries" runat="server" Width="150"></asp:DropDownList><cc1:CascadingDropDown ID="cdlCountries" TargetControlID="ddlCountries" PromptText="Select Country"
                PromptValue="" ServicePath="ServiceCS.asmx" ServiceMethod="GetCountries" runat="server"
                Category="CountryId" LoadingText="Loading..." /><asp:DropDownList ID="ddlStates" runat="server" Width="150"></asp:DropDownList><cc1:CascadingDropDown ID="cdlStates" TargetControlID="ddlStates" PromptText="Select State"
                PromptValue="" ServicePath="ServiceCS.asmx" ServiceMethod="GetStates" runat="server"
                Category="StateId" ParentControlID="ddlCountries" LoadingText="Loading..." />

Cs files

using System;
using System.Web;
using System.Web.Services;
using System.Data;
using MySql.Data.MySqlClient;
using System.Configuration;
using AjaxControlToolkit;
using System.Collections.Generic;

/// <summary>
/// Summary description for ServiceCS
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class ServiceCS : System.Web.Services.WebService
{
    [WebMethod]
    public CascadingDropDownNameValue[] GetCountries(string knownCategoryValues)
    {
        string puser = User.Identity.Name;
        string query = "select Dbname, Dbid from db where Username = '" + puser + "';";
        List<CascadingDropDownNameValue> countries = GetData(query);
        return countries.ToArray();
    }

    [WebMethod]
    public CascadingDropDownNameValue[] GetStates(string knownCategoryValues)
    {
        string country = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)["Dbid"];
        string query = string.Format(" select tableName, tableid from tableformula where Dbid = {0}", country);
        List<CascadingDropDownNameValue> states = GetData(query);
        return states.ToArray();
    }



    private List<CascadingDropDownNameValue> GetData(string query)
    {
        string conString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        MySqlCommand cmd = new MySqlCommand(query);
        List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
        using (MySqlConnection con = new MySqlConnection(conString))
        {
            con.Open();
            cmd.Connection = con;
            using (MySqlDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    values.Add(new CascadingDropDownNameValue
                    {
                        name = reader[0].ToString(),
                        value = reader[1].ToString()
                    });
                }
                reader.Close();
                con.Close();
                return values;
            }
        }
    }
}

the problem is in the getstates function


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>