I am new to AJAX. The scenario is I have two dropdown boxes. First one
has list of BANKs which is populated on the server side. Its
"AutoPostBack" property is False. I want to populate second DropDown
box with all the routings for the selected bank in the first DropDown.

I have created a server side AjaxMethod that populates the List of
routings for a given BANK (passed as argument). When I run this on the
server side it works fine. But the problem is when I invoke this method
from JavaScript, asynchronously, I am not sure if it executes or not,
because I always get the DataSet as NULL.

Here is my server side AjaxMethod:
                [AjaxMethod()]
                public DataSet GetRoutingsByFI(string FICode)
                {
                        SqlCommand cmd = new SqlCommand();
                        string query = "select FI_ROUTING from NAK_FI_ROUTING 
where FI_CODE
= @Code ";

                        cmd.Connection  = conn;
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = query;

                        SqlParameter pCode = new SqlParameter("@Code", 
SqlDbType.VarChar);
                        pCode.Value = FICode;
                        cmd.Parameters.Add(pCode);

                        SqlDataAdapter daRT = new SqlDataAdapter(cmd);
                        DataSet dsRT = new DataSet();

                        conn.Open();
                        daRT.Fill(dsRT);
                        conn.Close();

                        return dsRT;
                }


Here is my JavaScript code:

                function showRoutings()
                {
                        //alert("I am here ....");
                        var FIs = document.Form1.ddlFI;
                        var idx = FIs.selectedIndex;
                        var FI  = FIs.options[idx].value;

                        //alert(FI);

                        if (idx > 0)
                        {
                                alert(FI);
                        }
                        else
                        {
                                alert("Select a valid FI.");
                        }

                        FirstSample.WebForm1.GetRoutingsByFI(FI, 
showRoutings_CallBack);
                }

                function showRoutings_CallBack(response)
                {
                        var ds = response.value;

                        alert("I reached here in the callback function");

                        if (ds==null)
                        {
                                alert("DataSet is NULL.");
                        }
                        else if (typeof(ds) != "object")
                        {
                                alert("typeof(ds) is NOT Object");
                        }
                        else if (ds.Tables == null)
                        {
                                alert("ds.Tables is NULL");
                        }
                        else
                        {
                                alert("God knows what error is coming back.");
                        }

                        //if (ds!=null && typeof(ds)=="object" && 
ds.Tables!=null)
                        //{
                        //      for(var i=0; i<ds.Tables[0].Rows.length;i++)
                        //      {
                        //              alert(ds.Tables[0].Rows[i].FI_ROUTING);
                        //      }
                        //}

                }

I always get "DataSet is NULL" message.

If anyone can tell me how can I loop thru the DataSet in the JavaScript
and also how can I make sure that the AjaxMethod executed properly and
populated the DataSet, I will appreciate that.

This is just rough draft of code. I don't have proper error handling
and all, which I can do later once it works as required.

Thanks
Manjeet


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Ajax.NET Professional" group.

To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]

For more options, visit this group at http://groups.google.com/group/ajaxpro

The latest downloads of Ajax.NET Professional can be found at 
http://www.ajaxpro.info/

Don't forget to read my blog at http://weblogs.asp.net/mschwarz/

The open source project is now located at 
http://www.codeplex.com/Wiki/View.aspx?ProjectName=AjaxPro
-~----------~----~----~----~------~----~------~--~---

Reply via email to