Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys,

i have asp.net website,
where i'm using jqxgrid to bind data from a html table,
I have one add button in this table and i'm calling this ADD2Grid().

Code:
<script type="text/javascript">
        function ADD2Grid() {
            //Getting the source data with ajax GET request
            var tt = $('#ddltitle :selected').text() + "|" +
                $("#<%=txtfn.ClientID %>").val() + "|" +
                $("#<%=txtmn.ClientID %>").val() + "|" +
                $("#<%=txtln.ClientID %>").val();
            //alert(tt);
            source = {
                datatype: "xml",
                datafields: [
                { name: 'Title', type: 'string' },
                { name: 'First Name', type: 'string' },
                { name: 'Middle Name', type: 'string' },
                { name: 'Last Name', type: 'string' }
                ],
                async: false,
                record: 'Table',
                url: 'Default.aspx/GetCustomers',
                data: '{ data1:' + tt + '}',//Error
                success: alert(data.d)
            };
            var dataAdapter = new $.jqx.dataAdapter(source,
                {  contentType: 'application/json; charset=utf-8'}
            );
            $("#jqxgrid").jqxGrid({
                source: dataAdapter,
                theme: 'classic',
                columns: [
                    { text: 'Title', dataField: 'Title', width: 50 },
                    { text: 'First Name', dataField: 'First Name', width: 250 },
                    { text: 'Middle Name', dataField: 'Middle Name', width: 250 },
                    { text: 'Last Name', dataField: 'Last Name', width: 250 }
                ]
            });
        };
    </script>


Default.aspx
protected static DataSet GetData(string data)
        {
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            if (dt == null)
            {
                dt.Columns.Add("Title", typeof(string));
                dt.Columns.Add("First Name", typeof(string));
                dt.Columns.Add("Middle Name", typeof(string));
                dt.Columns.Add("Last Name", typeof(string));
            }
            else
            {
                dt = HttpContext.Current.Session["MyTable"] as DataTable;
            }

            string[] split = data.Split('|');

            DataRow dr = dt.NewRow();
            dr["Title"] = split[0];
            dr["First Name"] = split[1];
            dr["Middle Name"] = split[2];
            dr["Last Name"] = split[3];
            dt.Rows.Add(dr);

            HttpContext.Current.Session["MyTable"] = dt;

            ds.Tables.Add(dt);
            return ds;
        }

        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)]
        public static string GetCustomers(string data1)
        {
            // Populate the DataSet.
            DataSet data = GetData(data1);
            // return the Customers table as XML.
            StringWriter writer = new StringWriter();
            data.Tables[0].WriteXml(writer, XmlWriteMode.WriteSchema, false);
            return writer.ToString();
        }


Can any one please help me.


Thanks
Posted
Updated 2-Jun-15 0:29am
v2
Comments
raju melveetilpurayil 2-Jun-15 6:37am    
Have a look on here
http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/index.htm
http://www.jqwidgets.com/community/topic/dynamic-data-bind/
abdul subhan mohammed 2-Jun-15 6:40am    
Dude, i'm looking for the code how to pass arguments
abdul subhan mohammed 2-Jun-15 9:09am    
http://www.codeproject.com/Questions/997144/how-to-add-data-into-arrays-on-button-click-in-jqu
I think the issue is, you are posting data, but your method type is accepting only "get". Change that to post and also on "source", declare type: "POST".

Let me know what you found out after this.
abdul subhan mohammed 2-Jun-15 7:16am    
i'm getting this error:

Uncaught ReferenceError: data is not defined

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