Ajax下拉列表级联错误 [英] Ajax dropdownlist Cascading error

查看:76
本文介绍了Ajax下拉列表级联错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ajax下拉级联中,出现了这些错误.

System.NullReferenceException:对象引用未设置为对象的实例.
在DropdownWebService.BindCountrydropdown(StringknownCategoryValues,String类别)


我的代码是:

我在网络服务页面中的代码是:

In Ajax dropdown cascading i got these error.

System.NullReferenceException: Object reference not set to an instance of an object.
at DropdownWebService.BindCountrydropdown(String knownCategoryValues, String category)


My code is :

My code in webservice page is:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
 [System.Web.Script.Services.ScriptService]
public class DropdownWebService : System.Web.Services.WebService {

    [WebMethod]
    public CascadingDropDownNameValue[] BindCountrydropdown(string knownCategoryValues, string category)
    {
        SqlConnection concountry = new SqlConnection(ConfigurationManager.ConnectionStrings["cnnstring"].ConnectionString);
        concountry.Open();
        SqlCommand cmdcountry = new SqlCommand("select * from Country", concountry);
        SqlDataAdapter dacountry = new SqlDataAdapter(cmdcountry);
        cmdcountry.ExecuteNonQuery();
        DataSet dscountry = new DataSet();
        dacountry.Fill(dscountry);
        concountry.Close();
        List<cascadingdropdownnamevalue> countrydetails = new List<cascadingdropdownnamevalue>();
        foreach (DataRow dtrow in dscountry.Tables[0].Rows)
        {
            string CountryID = dtrow["CountryID"].ToString();
            string CountryName = dtrow["CountryName"].ToString();
            countrydetails.Add(new CascadingDropDownNameValue(CountryName, CountryID));
        }
        return countrydetails.ToArray();
    }
    [WebMethod]
    public CascadingDropDownNameValue[] BindStatedropdown(string knownCategoryValues, string category)
    {
        int CountryID;
        StringDictionary countrydetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        CountryID = Convert.ToInt32(countrydetails["Country"]);
        SqlConnection constate = new SqlConnection(ConfigurationManager.ConnectionStrings["cnnstring"].ConnectionString);
        constate.Open();
        SqlCommand cmdstate = new SqlCommand("select * from State where CountryID=@CountryID", constate);
        cmdstate.Parameters.AddWithValue("@CountryID", CountryID);
        cmdstate.ExecuteNonQuery();
        SqlDataAdapter dastate = new SqlDataAdapter(cmdstate);
        DataSet dsstate = new DataSet();
        dastate.Fill(dsstate);
        constate.Close();
        List<cascadingdropdownnamevalue> statedetails = new List<cascadingdropdownnamevalue>();
        foreach (DataRow dtstaterow in dsstate.Tables[0].Rows)
        {
            string stateID = dtstaterow["StateID"].ToString();
            string statename = dtstaterow["StateName"].ToString();
            statedetails.Add(new CascadingDropDownNameValue(statename, stateID));
        }
        return statedetails.ToArray();
    }
    [WebMethod]
    public CascadingDropDownNameValue[] BindRegiondropdown(string knownCategoryValues, string category)
    {
        int stateID;
        StringDictionary statedetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        stateID = Convert.ToInt32(statedetails["State"]);
        SqlConnection conregion = new SqlConnection(ConfigurationManager.ConnectionStrings["cnnstring"].ConnectionString);
        conregion.Open();
        SqlCommand cmdregion = new SqlCommand("Select * from Region where StateID=@StateID", conregion);
        cmdregion.Parameters.AddWithValue("@StateID", stateID);
        cmdregion.ExecuteNonQuery();
        SqlDataAdapter daregion = new SqlDataAdapter(cmdregion);
        DataSet dsregion = new DataSet();
        daregion.Fill(dsregion);
        conregion.Close();
        List<cascadingdropdownnamevalue> regiondetails = new List<cascadingdropdownnamevalue>();
        foreach (DataRow dtregionrow in dsregion.Tables[0].Rows)
        {
            string regionID = dtregionrow["RegionID"].ToString();
            string regionname = dtregionrow["RegionName"].ToString();
            regiondetails.Add(new CascadingDropDownNameValue(regionname, regionID));

        }
        return regiondetails.ToArray();
    }
} 


所以请帮我解决这个错误.


so plz help me out to solve this error.

推荐答案

错误为500时,表示它是内部错误,表示服务内部-服务引发了未被捕获的异常.
在服务上的 Windows事件日志中查看问题出在哪里.

另外,请尝试:
-在IE中转到菜单工具/Internet选项".
-单击高级"选项卡上的取消选中显示友好的HTTP错误消息"选项,然后单击确定".
-尝试再次访问您的网页.现在,您将看到更有意义的错误消息,它将帮助您解决问题.

其他可能性:
您托管服务的方式可能存在问题.可能是多个配置文件?
When the error is 500, that means it''s an internal error, meaning internal to the service - the service threw an exception that was not caught.
Look in the Windows event logs on the service to see what went wrong.

Also, try:
- Go to menu Tools/Internet Options in your IE.
- Click on the Advanced tab, uncheck "Show friendly HTTP error messages" option and click Ok.
- Try accessing your web page again. Now you will see much more meaningful error message which will help you to troubleshoot the problem.

Other possibility:
There might be an issue in the way you have hosted your service. May be multiple config files?


由于错误500是一般性错误,对于实际问题并没有多大帮助,我建议您在Web服务中使用 try..catch blocks获取有关问题根源的信息.
Since error 500 is a generic error and doesn''t tell much about the actual problem, I suggest that you use try..catch blocks in your web services the get information abuot the root cause of the problem.


这篇关于Ajax下拉列表级联错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆