Click here to Skip to main content
15,886,199 members
Articles / Programming Languages / Javascript

Cascaded dropdown using jQuery

Rate me:
Please Sign up or sign in to vote.
4.93/5 (12 votes)
28 May 2009CPOL2 min read 64.7K   1.4K   44  
Implementation of cascaded dropdowns using jQuery.
  • jquery.zip
    • Jquery
      • App_Code
      • App_Data
      • Bin
        • AjaxControlToolkit.dll
        • ar
          • AjaxControlToolkit.resources.dll
        • cs
          • AjaxControlToolkit.resources.dll
        • de
          • AjaxControlToolkit.resources.dll
        • es
          • AjaxControlToolkit.resources.dll
        • fr
          • AjaxControlToolkit.resources.dll
        • he
          • AjaxControlToolkit.resources.dll
        • hi
          • AjaxControlToolkit.resources.dll
        • it
          • AjaxControlToolkit.resources.dll
        • ja
          • AjaxControlToolkit.resources.dll
        • ko
          • AjaxControlToolkit.resources.dll
        • nl
          • AjaxControlToolkit.resources.dll
        • pt
          • AjaxControlToolkit.resources.dll
        • ru
          • AjaxControlToolkit.resources.dll
        • tr-TR
          • AjaxControlToolkit.resources.dll
        • zh-CHS
          • AjaxControlToolkit.resources.dll
        • zh-CHT
          • AjaxControlToolkit.resources.dll
      • Default.aspx
      • Default.aspx.cs
      • Default.js
      • jquery.validate.js
      • jquery-1.3.2.min.js
      • web.config
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;

/// <summary>
/// Summary description for HimJSON
/// </summary>
public class HimJSON
{
	public HimJSON()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public static string GetJSONString(DataTable Dt)
    {

        string[] StrDc = new string[Dt.Columns.Count];
        string HeadStr = string.Empty;

        for (int i = 0; i < Dt.Columns.Count; i++)
        {

            StrDc[i] = Dt.Columns[i].Caption;

            HeadStr += "\"" + StrDc[i] + "\" : \"" + StrDc[i] + i.ToString() + "¾" + "\",";
        }

        HeadStr = HeadStr.Substring(0, HeadStr.Length - 1);

        StringBuilder Sb = new StringBuilder();
        Sb.Append("{\"" + Dt.TableName + "\" : [");

        for (int i = 0; i < Dt.Rows.Count; i++)
        {

            string TempStr = HeadStr;
            Sb.Append("{");

            for (int j = 0; j < Dt.Columns.Count; j++)
            {

                TempStr = TempStr.Replace(Dt.Columns[j] + j.ToString() + "¾", Dt.Rows[i][j].ToString());
            }

            Sb.Append(TempStr + "},");
        }

        Sb = new StringBuilder(Sb.ToString().Substring(0, Sb.ToString().Length - 1));
        Sb.Append("]};");

        return Sb.ToString();
    }


}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
India India
g

Comments and Discussions