简体   繁体   English

CascadingDropDown错误

[英]CascadingDropDown Error

I am trying to get my cascading comboboxes to work, but am getting a [Method error 500]. 我试图让我的级联组合框正常工作,但是却遇到了[方法错误500]。 Any ideas? 有任何想法吗? I've searched online, the code should work....Thanks in advance for your help! 我已经在网上搜索过,该代码应该可以正常工作。...在此先感谢您的帮助!

ADDSTORY.ASPX: ADDSTORY.ASPX:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="addstory.aspx.cs" Inherits="addstory" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

... ...

<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ScriptManager1" runat="server" />

... ...

<td class="style3">
                <asp:DropDownList ID="selectproject" runat="server" Width="225"></asp:DropDownList>
                <asp:CascadingDropDown ID="ccd1" runat="server"
                ServicePath="~/dropdown.asmx?company=<%=co_id %>" ServiceMethod="GetProjects"
                TargetControlID="selectproject" Category="Project"
                PromptText="Select Project" />
                </td>

            </tr>

            <tr>
            <td class="style3"></td>
            <td width = "150" class="style3">Iteration:</td>

            <td class="style3">
                <asp:DropDownList ID="selectiteration" runat="server" Width="225"></asp:DropDownList>
                <asp:CascadingDropDown ID="ccd2" runat="server"
                ServicePath="~/dropdown.asmx?company=<%=co_id %>" ServiceMethod="GetIterations"
                TargetControlID="selectiteration" Category="Iteration"
                PromptText="Select Iteration" />
                </td>

            </tr>

DROPDOWN.ASMX: DROPDOWN.ASMX:

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

/// <summary>
/// Summary description for WebService
/// </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 dropdown : System.Web.Services.WebService
{
private string GetConnectionString()
{
    return System.Configuration.ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString;
}

[WebMethod]

public CascadingDropDownNameValue[] GetProjects(string knownCategoryValues, string category)
{

    string co_id = this.Context.Request.QueryString["company"].ToString();

    SqlConnection conn = new SqlConnection(GetConnectionString());
    conn.Open();
    SqlCommand comm = new SqlCommand("Select ProjectName, ProjectID FROM Project WHERE CompanyID = '" + co_id + "'", conn);
    SqlDataReader dr = comm.ExecuteReader();
    List<CascadingDropDownNameValue> l = new List<CascadingDropDownNameValue>();
    while (dr.Read())
    {
        l.Add(new CascadingDropDownNameValue(dr["ProjectName"].ToString(), dr["ProjectID"].ToString()));
    }
    conn.Close();
    return l.ToArray();
}

[WebMethod]

public CascadingDropDownNameValue[] GetIterations(string knownCategoryValues, string category)
{
    int ProjectID;
    StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

    if (!kv.ContainsKey("Project") || !Int32.TryParse(kv["Project"], out ProjectID))
    {
        throw new ArgumentException("Couldn't find project.");
    };

    SqlConnection conn = new SqlConnection(GetConnectionString());
    conn.Open();
    SqlCommand comm = new SqlCommand("SELECT Select CONVERT(VARCHAR(10), StartDate, 103) + ' - ' + CONVERT(VARCHAR(10), EndDate, 103) AS Iteration, ProjectIterationID FROM Iterations WHERE ProjectID=@ProjectID", conn);

    comm.Parameters.AddWithValue("@ProjectID", ProjectID);
    SqlDataReader dr = comm.ExecuteReader();
    List<CascadingDropDownNameValue> l = new List<CascadingDropDownNameValue>();

    while (dr.Read())
    {
        l.Add(new CascadingDropDownNameValue(dr["Iteration"].ToString(), dr["ProjectIterationID"].ToString()));
    }
    conn.Close();
    return l.ToArray();
}

}

I see you have already flagged your service as ScriptService, however you forgot to flag individual methods with the [ScriptMethod] attribute. 我看到您已经将服务标记为ScriptService,但是您忘记了使用[ScriptMethod]属性标记各个方法。

Also in the service path property of your cascading drop down controls I would take out the ~ and just use /dropdown.asmx 同样在级联下拉控件的服务路径属性中,我将取出~并仅使用/dropdown.asmx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM