无法在asp.net中调试Casecade下拉列表的Web服务 [英] Unable to debug webservice for casecade dropdown list in asp.net

查看:55
本文介绍了无法在asp.net中调试Casecade下拉列表的Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,
我在casecade下拉菜单中遇到问题.我有两个下拉菜单,一个用于国家,另一个用于国家.国家下拉列表具有约束力,但更改国家/地区状态下拉列表则不具有约束力.

下面给出了webservice和aspx页面的所有代码.
请提出建议.

aspx页面代码:

Dear All,
I am having problem in casecade dropdown .I have two dropdown one for country and another for State. Country dropdown binding but on change of country state dropdown in not binding.

All code of webservice and aspx page are given below.
Please suggest .

Aspx Page code:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPageInnerHTML.master" AutoEventWireup="true"

    CodeFile="CasecadeDrop.aspx.cs" Inherits="CasecadeDrop" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPart" runat="Server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <table width="100%" align="center" style="height: 50px">
        <tr>
            <td align="right">
                Country:&nbsp;&nbsp;
            </td>
            <td align="left">
                &nbsp;&nbsp;<asp:DropDownList ID="ddlCountry" runat="server" Width="250px">
                </asp:DropDownList>
                <cc1:CascadingDropDown ID="ccddCountry" ServicePath="CasecadeDropdown.asmx" ServiceMethod="GetCountry"

                    Category="Country" runat="server" TargetControlID="ddlCountry" PromptText="Select Country"

                    LoadingText="Loading Countries..">
                </cc1:CascadingDropDown>
            </td>
        </tr>
        <tr>
            <td align="right">
                State:&nbsp;&nbsp;
            </td>
            <td align="left">
                &nbsp;&nbsp;
                <asp:DropDownList ID="ddlState" runat="server" Width="250px">
                </asp:DropDownList>
                <cc1:CascadingDropDown ID="ccddState" ServicePath="CasecadeDropdown.asmx" ServiceMethod="GetState"

                    Category="State" runat="server" TargetControlID="ddlState" PromptText="Select State">

                </cc1:CascadingDropDown>
            </td>
        </tr>
    </table>
</asp:Content>



Web服务代码




Webservice code


using System;
using System.Web;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web.Services;
using System.Web.Services.Protocols;
using AjaxControlToolkit;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

[System.Web.Script.Services.ScriptService ]
/// <summary>
/// Summary description for CasecadeDropdown
/// </summary>
[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 CasecadeDropdown : System.Web.Services.WebService 
{
    string Constr = ConfigurationManager.AppSettings["MyConnectionString"].ToString();

    public CasecadeDropdown ()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string HelloWorld() 
    {
        return "Hello World";
    }

    [WebMethod]
    public CascadingDropDownNameValue[] GetCountry(string knownCategoryValues, string category)
    {
        int Qtype=1;
        SqlConnection connection = new SqlConnection(Constr);
        connection.Open();
        SqlCommand command = new SqlCommand("TempGetCountryStateNew", connection);
        command.CommandType = CommandType.StoredProcedure;
        command.Parameters.Add("@Qtype", SqlDbType.Int).Value = Qtype;
        SqlDataAdapter adap = new SqlDataAdapter(command);
        DataSet ds=new DataSet ();
        adap.Fill(ds);
        connection.Close();
         List<cascadingdropdownnamevalue> countrydetails = new List<cascadingdropdownnamevalue>();
         foreach(DataRow dtrow in ds.Tables[0].Rows)
           {
               string CountryID = dtrow["Country_Code"].ToString();
               string CountryName = dtrow["Country_Name"].ToString();
           countrydetails.Add(new CascadingDropDownNameValue(CountryName, CountryID));
           }
         return countrydetails.ToArray();
    }
   
    [WebMethod]
    public CascadingDropDownNameValue[] GetState(string knownCategoryValues, string category)
    {
        int Qtype = 2;
        int countryID;
       //This method will return a StringDictionary containing the name/value pairs of the currently selected values

        StringDictionary countrydetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        countryID = Convert.ToInt32(countrydetails["Country"]);

        //StringDictionary countrydetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        //countryID = Convert.ToString(countrydetails["Country"]);
        //StringDictionary kv =CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        //int DeptID;
        //if (!kv.ContainsKey("Country") || !Int32.TryParse(kv["Country"], out DeptID))
        //{
        //    return null;
        //}

        SqlConnection connection = new SqlConnection(Constr);
        connection.Open();
        SqlCommand command = new SqlCommand("TempGetCountryStateNew", connection);
        command.CommandType = CommandType.StoredProcedure;
        command.Parameters.Add("@Qtype", SqlDbType.Int).Value = Qtype;
        command.Parameters.Add("@CountryCode", SqlDbType.Int).Value = Convert .ToInt32(countryID);
        SqlDataAdapter adap = new SqlDataAdapter(command);
        DataSet ds = new DataSet();
        adap.Fill(ds);
        connection.Close();
        List<cascadingdropdownnamevalue> Statedetails = new List<cascadingdropdownnamevalue>();
        foreach (DataRow dtrow in ds.Tables[0].Rows)
        {
            string StateCode = dtrow["State_code"].ToString();
            string StateName = dtrow["State_name"].ToString();
            Statedetails.Add(new CascadingDropDownNameValue(StateName, StateCode));
        }
        return Statedetails.ToArray();
        
    }
}

推荐答案

您好Bhanu,

根据我提供的代码的理解,当服务启动时,您将数据绑定到下拉列表中,但是当下拉列表值更改时,我找不到任何被调用的方法.我的意思是没有方法被调用该事件.我在这里错过了什么吗?请让我知道..
Hi Bhanu,

As per my understanding from the code provided, you are binding the data to the drop down when the service starts.But i am not able to find any method that is called when the dropdown value is changed.I mean no method is being called for that event.Am i missing something here?Please let me know..


// 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 CasecadeDropdown : System.Web.Services.WebService
{
    string Constr = ConfigurationManager.AppSettings["MyConnectionString"].ToString();

    public CasecadeDropdown ()
    {

        //Uncomment the following line if using designed components
        //InitializeComponent();
    }


在您的Web服务中,您必须从


in your webservice you must to remove comment line from

// [System.Web.Script.Services.ScriptService]
public class CasecadeDropdown : System.Web.Services.WebService
{



像这样



like this

 [System.Web.Script.Services.ScriptService]
public class CasecadeDropdown : System.Web.Services.WebService
{



并将其添加到您的状态层叠下拉菜单



and pls add this to your state cascadedropdown

ParentControlID="ddlCountry"



在这里编辑



and edit here

List<cascadingdropdownnamevalue> countrydetails = new List<cascadingdropdownnamevalue>();







to

List<CascadingDropDownNameValue> countrydetails = new List<CascadingDropDownNameValue>();



因为c#是区分大小写的语言



because of c# is a case sensitive language


^ ],请访问此网站,您会找到您的要求....
http://stackoverflow.com/questions/10466809/cascading-drop-down-giving-undefined-values-in-chrome-and-blank-fields[^] refer this website you will find out your requirements....


这篇关于无法在asp.net中调试Casecade下拉列表的Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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