Click here to Skip to main content
15,891,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
function addRow(tableID) {

            var table = document.getElementById(tableID);

            var rowCount = table.rows.length;
            var row = table.insertRow(rowCount);

//           dataTable dt=new dataTable();
//           dataRow dr=;


            var colCount = table.rows[0].cells.length;

            for (var i = 0; i < colCount; i++) {

                var newcell = row.insertCell(i);

                newcell.innerHTML = table.rows[0].cells[i].innerHTML;
                //alert(newcell.childNodes);
                switch (newcell.childNodes[0].type) {
                    case "text":
                        newcell.childNodes[0].value = "";
                        break;
                    case "checkbox":
                        newcell.childNodes[0].checked = false;
                        break;
                    case "select-one":
                        newcell.childNodes[0].selectedIndex = 0;
                        break;
                }
            }
        }

        function deleteRow(tableID) {
            try {
                var table = document.getElementById(tableID);
                var rowCount = table.rows.length;

                for (var i = 0; i < rowCount; i++) {
                    var row = table.rows[i];
                    var chkbox = row.cells[0].childNodes[0];
                    if (null != chkbox && true == chkbox.checked) {
                        if (rowCount <= 1) {
                            alert("Cannot delete all the rows.");
                            break;
                        }
                        table.deleteRow(i);
                        rowCount--;
                        i--;
                    }


                }
            } catch (e) {
                alert(e);
            }
        }

    </script>
</head>
<body>
    <input type="button" name="btnSave" value="Save" />
    <input type="button" value="Add Row" onclick="addRow('dataTable')" />

    <input type="button" value="Delete Row" onclick="deleteRow('dataTable')" />
    <table id="table1" width="400px" border="0">
    <tr>
    <td style="padding-left:30px">Name</td>
    <td style="padding-left:120px">Email</td>
    <td style="padding-left:125px">Contacts</td>
    </tr>
    <table id="dataTable" width="350px" border="1">
        <tr>
            <td><input type="checkbox" name="chk"/></td>
            <td><input type="text" name="txt1" /></td>
            <td><input type="text" name="txt"/></td>
            <td>
                <select name="country">
                    <option value="in">Collage</option>
                    <option value="de">Students</option>
                    <option value="fr">c</option>
                    <option value="us">d</option>
                    <option value="ch">e</option>
                </select>
            </td>
        </tr>
    </table>

    </table>
</body>
</html>



web service part

C#
 protected void Page_Load(object sender, EventArgs e)
        {
            getstudents();
        }
        public void getstudents()
        {
            long keycolvalue = -1;
            string sortcolvalue = "";
            string XML = "";
            string error = "";
            long objtype = 3;

            PropertyInfo[] propInfo1 = new PropertyInfo[2];
            propInfo1[0] = new PropertyInfo();
            propInfo1[0].propertyID = 22140;
            propInfo1[0].propValue = "1";
            propInfo1[0].relJoinID = 15;

            long contains = 1;
            long sortcolid = -1;
            bool filter;

            try
            {
                ServiceBO obj = new ServiceBO();
                obj.GetStudents(objtype, propInfo1, contains, keycolvalue, sortcolvalue, sortcolid, out filter, out XML, out error);

                if (XML != "")
                {
                    DataTable table = new DataTable();
                    table.Columns.Add("Name", typeof(string));
                    table.Columns.Add("Email", typeof(string));
                    XmlDocument doc = new XmlDocument();

                    doc.LoadXml(XML);
                    XmlNodeList listNode = doc.SelectNodes(@"Result/Data/R");
                    int k = 0, j = 2, i = 0, cou = 0;
                    cou = (int)listNode.Count;

                    foreach (XmlElement node in listNode)
                    {
                        table.Rows.Add(listNode[k].ChildNodes[2].InnerText.ToString(), listNode[k].ChildNodes[3].InnerText.ToString());
                        k++;
                    }
                }

                else
                {
                    Response.Write("Server error occured.");
                }
            }

            catch (Exception ex)
            {

            }
        }
    }
}


i am getting textbox dynamically on alick of addrow bt now i want to add data through web services...
Posted
Updated 9-Jul-12 1:21am
v3
Comments
Ganesan Senthilvel 9-Jul-12 6:53am    
code format
programerajay 9-Jul-12 7:13am    
please anyone can help me..
thanks in advance...
[no name] 9-Jul-12 7:14am    
Very nice code dump. It there a question to go along with it coming soon?
programerajay 9-Jul-12 7:30am    
yes now i want to use it using xmlhttprequest..... i need some guidance....:)

1 solution

You want to know how to talk to server from Javascript. Call server side, talk to webservice and get the data.

There are few ways to interact with server side through client side(Javascript):
1. XMLHttpRequest[^]
2. Callback[^]
3. WebService call[^]
4. PageMethod[^]

Pick one that suits you and implement it.
 
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