Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,
I have small problem in Json. In the code below
JavaScript
loadEmployeeCars($("select option:selected").val())
is not executing.
If I want to execute to the the method what should I do?

ASPX:
<script language="javascript" type="text/javascript">

        $(function() {

            var $ddl = $("select[name$=ddlEmployee]");

            var $ddlCars = $("select[name$=ddlEmployeeCars]");

            $ddl.focus();

            $ddl.bind("change keyup", function() {

                if ($(this).val() != "0") {

                    loadEmployeeCars($("select option:selected").val());                    

                    $ddlCars.fadeIn("slow");

                } else {

                    $ddlCars.fadeOut("slow");

                }

            });

        });



        function loadEmployeeCars(selectedItem) {

            $.ajax({

                type: "POST",

                url: "DropdowndemoJson.aspx/getdataset",

                data: "{docid: " + selectedItem + "}",

                contentType: "application/json; charset=utf-8",

                dataType: "json",

                async: true,

                success: function Success(data) {

                    printEmployeeCars(data.d);

                }

            });

        }        



        function printEmployeeCars(data) {

            $("select[name$=ddlEmployeeCars] > option").remove();

            for (var i = 0; i < data.length; i++) {

                $("select[name$=ddlEmployeeCars]").append(

                    $("<option></option>").val(data[i].docid).html(data[i].docname)

                );

            }

        }       

    </script>

  <asp:dropdownlist id="ddlEmployee" runat="server" appenddatabounditems="true" xmlns:asp="#unknown">

            <asp:listitem text="(Please Select)" value="0" selected="True" />

        </asp:dropdownlist>

        <asp:dropdownlist id="ddlEmployeeCars" runat="server" xmlns:asp="#unknown">

        </asp:dropdownlist>

Code Behind:
C#
//aspx.cs:
    protected void Page_Load(object sender, EventArgs e)

    {

        fillemp();

        fillempcars();

       

    }



    private void fillempcars()

    {

        string s2= "select * from deptmaster";

        SqlDataAdapter ad1 = new SqlDataAdapter(s2, con);

        DataSet ds2= new DataSet();

        ad1.Fill(ds2);

       ddlEmployeeCars.DataTextField = "deptid";

       ddlEmployeeCars.DataValueField = "deptname";

       ddlEmployeeCars.DataSource = ds2;

       ddlEmployeeCars.DataBind();

    }



    private void fillemp()

    {

        string s = "select * from docmaster";

        SqlDataAdapter ad1 = new SqlDataAdapter(s,con);

        DataSet ds1 = new DataSet();

        ad1.Fill(ds1);

        ddlEmployee.DataTextField = "docname";

        ddlEmployee.DataValueField = "docname";

        ddlEmployee.DataSource = ds1;

        ddlEmployee.DataBind();

    }

    public void getdataset(int deptid)

    {

       

        string query = "select d.deptid,d.deptname  from deptmaster d, docmaster doc where doc.deptid=d.deptid and doc.docid='"+ddlEmployee.SelectedValue+"' ";

        SqlDataAdapter ad = new SqlDataAdapter(query, con);

        DataSet ds = new DataSet();

        ad.Fill(ds);

       

    }


Best Regards,

Thiru
Posted
Updated 20-May-10 10:03am
v3
Comments
Sandeep Mewara 20-May-10 4:10am    
Please use Tag's next time you post question. They are your friends while posting questions properly. Please format the question properly.
Sandeep Mewara 20-May-10 9:28am    
You have not updated the question nor added what's your problem. You need to be little more specific then just posting the full code out here.

1 solution

For one, the getdataset method does not return anything.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900