나는이 드롭 다운을 가지고 첫 번째 드롭 잘 작동하고 데이터베이스에서 데이터를 표시하지만 아래 두 번째 드롭 여기에 오류 (500)를 보여줍니다 웹 서비스에 대한 내 코드입니다 :이 방법의 오류를 보여줍니다 500
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Configuration;
using System.Data.SqlClient;
using System.Collections.Specialized;
using AjaxControlToolkit;
using System.Data;
[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 CascadingDropdown : System.Web.Services.WebService
{
private static string strconnection = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
//private static string strconnection = ConfigurationManager.AppSettings["ConnectionString"].ToString();
SqlConnection concategory = new SqlConnection(strconnection);
public CascadingDropdown()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public CascadingDropDownNameValue[] BindCategoryDetails(string knownCategoryValues, string category)
{
concategory.Open();
SqlCommand cmdcategory = new SqlCommand("select * from Categories", concategory);
//create list and add items in it by looping through dataset table
List<CascadingDropDownNameValue> categorydetails = new List<CascadingDropDownNameValue>();
SqlDataReader drcategory= null ;
drcategory=cmdcategory.ExecuteReader();
while(drcategory.Read())
{
string CategoryID = drcategory ["categoryID"].ToString();
string CategoryName = drcategory ["categoryName"].ToString();
categorydetails.Add(new CascadingDropDownNameValue(CategoryName, CategoryID));
}
concategory.Close();
return categorydetails.ToArray();
}
/// <summary>
/// WebMethod to Populate State Dropdown
/// </summary>
[WebMethod]
public CascadingDropDownNameValue[] BindProductDetails(string knownCategoryValues, string category)
{
int categoryID;
//This method will return a StringDictionary containing the name/value pairs of the currently selected values
StringDictionary categorydetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
categoryID = Convert.ToInt32(categorydetails["Category"]);
concategory.Open();
SqlCommand cmdproduct = new SqlCommand("select * from Products where [email protected]", concategory);
cmdproduct.Parameters.AddWithValue("@categoryID", categoryID);
//create list and add items in it by looping through dataset table
List<CascadingDropDownNameValue> productdetails = new List<CascadingDropDownNameValue>();
SqlDataReader drproduct= null ;
drproduct=cmdproduct.ExecuteReader();
while(drproduct.Read()) {
string ProductID = drproduct ["categoryID"].ToString();
string ProductName = drproduct ["categoryName"].ToString();
productdetails.Add(new CascadingDropDownNameValue(ProductName, ProductID));
}
concategory.Close();
return productdetails.ToArray();
}
}
및 영문 코드 : U이 필요로하는 다른 THER의 아무것도 말해
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="false"%>
<%@ Register Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" tagPrefix="ajax" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<asp:DropDownList ID="ddlcategory" runat="server"></asp:DropDownList>
<ajax:CascadingDropDown ID="ccdCategory" runat="server" Category="category"
TargetControlID="ddlcategory" PromptText="Select Category"
LoadingText="Loading Categories" ServiceMethod="BindCategoryDetails"
ServicePath="CascadingDropdown.asmx">
</ajax:CascadingDropDown>
<asp:DropDownList ID="ddlproduct" runat="server">
</asp:DropDownList>
<ajax:CascadingDropDown ID="ccdProduct" runat="server" Category="product"
TargetControlID="ddlproduct" PromptText="Select Product"
LoadingText="Loading Products" ServiceMethod="BindProductDetails"
ScriptPath="CascadingDropdown.asmx">
</ajax:CascadingDropDown>
</form>
</body>
</html>
가 있는지 확인합니다. 감사.
의해 대체되어야한다. ToString()를 ; 그것은 ProductID가 아니어야합니까? –