Tuesday, April 17, 2012

AJAX - Cascading DropDown List WebSerive database binding

Everything's great with official ASP.NET tutorials and videos concerning the Cascading DropDown Lists... they just forgot to mention one important thing without you will get am WebMethod Error 500. - is to uncomment one line in the asmx file (Marked in Yellow):

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

/// <summary>
/// Summary description for new_ad_service
/// </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.
public class new_ad_service : System.Web.Services.WebService {

    public new_ad_service ()
        //Uncomment the following line if using designed components

    public CascadingDropDownNameValue[] get_Data()
        List<CascadingDropDownNameValue> my_list = new List<CascadingDropDownNameValue>();

        DataTable dt = DAL.get_provinces(); //gets DataTable from SQL server db
        foreach (DataRow dr in dt.Rows)
            my_list.Add(new CascadingDropDownNameValue(dr[0].ToString(), dr[0].ToString()));
        return my_list.ToArray();


No comments:

Post a Comment