Click here to Skip to main content
12,634,788 members (30,561 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#2.0 C# Javascript
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

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 9-Jul-12 1:47am
Updated 9-Jul-12 2:21am
v3
Comments
GanesanSenthilvel 9-Jul-12 6:53am
   
code format
programerajay 9-Jul-12 7:13am
   
please anyone can help me..
thanks in advance...
Wes Aday 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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 9 Jul 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100