Click here to Skip to main content
15,868,070 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hai friends i am using jqwidgets plugin to populate table data.
my requirement is to display data on table by the combobox selection
i am using asp.net
my problem is how to pass parameter to function “GetCustomersfn(string cusID)”
if i use parameter less function ie GetCustomersfn() i get the expected result.
please help..

Function given below
C#
[WebMethod]
   [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)]
   public string GetCustomersfn(string cusID)
   {
       string query = "SELECT * FROM Customers WHERE CustomerID LIKE @CustomerID";
       string tablename = "Customers";
       SqlCommand cmd = new SqlCommand(query);
       cmd.Parameters.AddWithValue("CustomerID", "%" + cusID.Substring(0, 1) + "%");
       DataSet data = GetData(cmd, tablename);
       //return GetData(cmd, tablename).GetXml();
       System.IO.StringWriter writer = new System.IO.StringWriter();
       data.Tables[0].WriteXml(writer, XmlWriteMode.WriteSchema, false);
       return writer.ToString();

   }

script file is given below
JavaScript
<script type="text/javascript">
            $(document).ready(function () {
                $('#dlcustomers').change(function () {
                    //            var obj = {};
                    //            obj.cusID = $.trim($("[id*=dlcustomers]").val());
                    //            alert(obj.cusID);
                    var cid = $.trim($("[id*=dlcustomers]").val());
                                alert(cid);

                    source = {
                        datatype: "xml",
                        datafields: [
                                        { name: 'CompanyName' },
                                        { name: 'ContactName' },
                                        { name: 'ContactTitle' },
                                        { name: 'City' },
                                        { name: 'Country' },
                                        { name: 'Address' }
                                    ],
                        async: false,
                        record: 'Customers',
                        url: 'DataWebService.asmx/GetCustomersfn',
                        data: { CusID: 'A'}
                        
                    };
                    var dataAdapter = new $.jqx.dataAdapter(source,
                { contentType: 'application/json; charset=utf-8' }
            );
                    $("#dataTable").jqxDataTable(
            {
                width: 850,
                height: 400,
                source: dataAdapter,
                pagerButtonsCount: 10,
                pageable: true,
                columnsresize: true,
                altRows: true,
                filterable: true,
                sortable: true,
                filtermode: 'advanced',
                // pagerMode: 'advanced',
                //  groups: ['City'],
                columns: [
                    { text: 'Company Name', dataField: 'CompanyName', width: 250 },
                    { text: 'Contact Name', dataField: 'ContactName', width: 150 },
                    { text: 'Contact Title', dataField: 'ContactTitle', width: 180 },
                    { text: 'Address', dataField: 'Address', width: 180 },
                    { text: 'City', dataField: 'City', width: 80 },
                    { text: 'Country', dataField: 'Country', width: 100 }
                ]
            });
                });
            });
    </script>



please help.. thanks in advance
Posted
Updated 23-Jun-17 22:05pm

Refer - Send (Pass) multiple parameters to WebMethod in jQuery AJAX POST in ASP.Net[^] and try this technique.

Use Json Stringify.
 
Share this answer
 
thanks for your advice thanks for your advice thanks for your advice
 
Share this answer
 
v2
Comments
ashish1985s 29-Oct-14 5:12am    
i have same problem can you please show me some sample for how you did that
Thanks

Ashish Shah
jinesh sam 30-Oct-14 7:20am    
@ashish1985s
s i will post the code
this is the web service code i used

C#
[WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string trialbalancetotal(string ParishName, Int32 FiscalYear, string sdate = null, string edate = null)
    {
        string tablename = "Trial";
        SqlCommand cmd = new SqlCommand("spDisplayTrialBalanceTotal");
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@ParishName", ParishName);
        cmd.Parameters.AddWithValue("@yr", FiscalYear);

        if (sdate != "")
        {
            DateTime strtdate, enddate;
            strtdate = DateTime.ParseExact(sdate, "MM/dd/yyyy", CultureInfo.InvariantCulture);
            enddate = DateTime.ParseExact(edate, "MM/dd/yyyy", CultureInfo.InvariantCulture);

            cmd.Parameters.Add("@startdate", SqlDbType.DateTime).Value = strtdate;//.ToString("MM/dd/yyyy");
            cmd.Parameters.Add("@enddate", SqlDbType.DateTime).Value = enddate;//.ToString("MM/dd/yyyy");  
        }
        return GetData_reader(cmd, tablename);
    }


Javascript code
JavaScript
$.fn.trialbalancetotal = function () {
    var obj = {};
    var checktype = $("#RadioDiv input:radio:checked").val()
    if (checktype == 'Year Wise') {
        obj.ParishName = $('#HF').val();
        obj.FiscalYear = $("#jqxDropDownListYear").jqxDropDownList('val');
        obj.sdate = "";
        obj.edate = "";

    }
    else {
        obj.ParishName = $('#HF').val();
        obj.FiscalYear = $("#jqxDropDownListYear").jqxDropDownList('val');
        obj.sdate = $('#jqxDateTimeInputstart').jqxDateTimeInput('val');
        obj.edate = $('#jqxDateTimeInputend').jqxDateTimeInput('val');
        //  alert(obj.sdate);

    }
    $.ajax({
        type: "POST",
        url: "../DataWebService.asmx/trialbalancetotal",
        data: JSON.stringify(obj),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            var obj = JSON.parse(data.d);
            //alert(obj.Trial[0].Balance);
            $("#Balance").html('Balance :' + obj.Trial[0].Balance);
            $("#Openbalance").html('Opening:' + obj.Trial[0].OpenBalance);
            $("#Closebalance").html('Closing:' + obj.Trial[0].CloseBalance);
            $("#Income").html('Income:' + obj.Trial[0].Income);
            $("#Expense").html('Expense:' + obj.Trial[0].Expense);
            $("#btnbank").show();
        },
        error: function (error) {
            alert("Error in the trialbalancetotal call");
        }
    });
}


Hope this help
 
Share this answer
 
remove the string cusID from public string GetCustomersfn(string cusID), remove the WHERE CustomerID LIKE @CustomerID from the query variable, also remove this cmd.Parameters.AddWithValue("CustomerID", "%" + cusID.Substring(0, 1) + "%");, and remove data: { CusID: 'A'} inside document.ready in aspx page and it will totally work..!
 
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