Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Professional Ajax ISBN: 978-0-471-77778-6
This is the forum to discuss the Wrox book Professional Ajax by Nicholas C. Zakas, Jeremy McPeak, Joe Fawcett; ISBN: 9780471777786
Important: For the new 2nd edition of this book, please post here instead: [url="http://p2p.wrox.com/forum.asp?FORUM_ID=307"]http://p2p.wrox.com/forum.asp?FORUM_ID=307[/url]
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Ajax ISBN: 978-0-471-77778-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 2nd, 2006, 07:11 AM
Registered User
 
Join Date: Sep 2006
Location: Vadodara, Gujrat, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default dropdownlistboxes in Ajax with asp.net 2.0


  I have given reference of Ajax.dll in my project. there are 2 dropdownlist boxes (one is for country and other one is for State) in one form. they are interrelated means if i select any country, depends on that i will get states's list in my other dropdownlistbox.


This is code is working...

 I writed down code in sample.aspx page:

<script language="javascript" type="text/javascript">
<!--
   function ClientGetStates(ddlCountry)
   {
    var countryId = ddlCountry.options[ddlCountry.selectedIndex].value;
    if (countryId > 0)
       {
PresentationLayer_JobSeeker_frmJobSeekerRegistrati on.GetStates(countryId,LoadStates_CallBack

);
        }
    }


       function LoadStates_CallBack(response)
        {
            if (response.error != null)
                {
                    alert(response.error);
                    return;
                }

            var states = response.value;
            if (states == null || typeof(states) != "object")
                {
                    return;
                }
            var statesList = document.getElementById("ddlState");
            statesList.options.length=0;
            for (var i = 0; i < states.length; ++i)
                {
                    statesList.options[statesList.options.length] = new

Option(states[i].State_Name, states[i].State_ID);
                }
        }

// -->
</script>


    <select id="ddlCountry" language="javascript" onchange="ClientGetStates(this)"

runat="server"> </select>

       <select id="ddlState" datatextfield="State_Name" datavaluefield="State_ID"

language="javascript"></select>



In Sample.aspx.cs File:


  protected void Page_Load(object sender, EventArgs e)
    {
       Ajax.Utility.RegisterTypeForAjax(typeof(Sample));
    }

    [Ajax.AjaxMethod()]
    public static DataView GetStates(Int32 iCountryIndex)
    {
        System.Data.DataView dv = new

System.Data.DataView(((DataTable)ParamState.ShowSe lected(iCountryIndex).Tables[0]));
        return dv;

    }


I want to run ddlState on server means (runat=server). at that time i m writing this code but this code is not running. can u suggest if i want to run this further code want to be run that what should i have to do.
This is not working ....



<script language="javascript" type="text/javascript">
<!--
   function ClientGetStates(ddlCountry)
   {
    var countryId = ddlCountry.options[ddlCountry.selectedIndex].value;
    if (countryId > 0)
       {
PresentationLayer_JobSeeker_frmJobSeekerRegistrati on.GetStates(countryId,LoadStates_CallBack

);
        }
    }

       function LoadStates_CallBack(response)
        {
            if(response.value == true)
                {
                    alert("You have changed");
                }
        }


// -->
</script>


    <select id="ddlCountry" language="javascript" onchange="ClientGetStates(this)"

runat="server"> </select>

      <select id="ddlState" datatextfield="State_Name" datavaluefield="State_ID"

runat="server"> </select>


In Sample.aspx.cs File:


  protected void Page_Load(object sender, EventArgs e)
    {
       Ajax.Utility.RegisterTypeForAjax(typeof(Sample));
    }

    [Ajax.AjaxMethod()]
    public static bool GetStates(Int32 iCountryIndex)
    {

        ddlState.Items.Clear();
        ddlState.DataSource = ParamState.ShowSelected(iCountryIndex).Tables[0].DefaultView;
        ddlState.DataTextField = "State_Name";
        ddlState.DataValueField = "State_ID";
        ddlState.DataBind();
        return true;
    }









Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET 2.0 Ajax raminriahi General .NET 2 September 5th, 2007 12:48 PM
Turning a regular ASP.NET App into an AJAX ASP.Net donrafeal7 Ajax 2 August 31st, 2007 12:33 AM
Asp.net ajax everest General .NET 0 March 8th, 2007 12:21 AM
ASP.NET AJAX inkrajesh ASP.NET 2.0 Professional 3 January 19th, 2007 03:42 PM
using AJAX in ASP.Net muskaanbajaj ASP.NET 1.0 and 1.1 Professional 3 February 24th, 2006 05:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.