locked
TableData RRS feed

All replies

  • User-1171043462 posted

    TableData is a DataTable

     using (var sda = new SqlDataAdapter())  
                   {  
                       cmd.Connection = con;  
                       sda.SelectCommand = cmd;  
                       TableData.Clear();  
                       sda.Fill(TableData);  

    Sunday, July 29, 2018 7:51 AM
  • User-369506445 posted

    hi

    in the sample using an ajax for display data into a table

    function getDetails() {  
        $.ajax({  
            type: "POST",  
            contentType: "application/json; charset=utf-8",  
            url: "Default.aspx/GetData", //Default.aspx is page and GetData is the WebMethod  
            data: {},  
            dataType: "json",  
            success: function(data) {  
                $('#dataTables-example tbody').remove(); // Every time I am removing the body of Table and applying loop to display data  
                //console.log(data.d);    
                for (var i = 0; i < data.d.length; i++) {  
                    $("#dataTables-example").append(  
                        "<tr><td>" + data.d[i].FName + "</td><td>" + data.d[i].Email + "</td>" +  
                        "<td>" + data.d[i].HomeMobile + "</td>" + "<td>" + data.d[i].OfficeMobile + "</td>" +  
                        "<td>" + data.d[i].Doj + "</td>" + "<td>" + data.d[i].Dob + "</td>" +  
                        "<td>" + "<input type='button' class='btn btn-primary editButton' data-id='" + data.d[i].EmpId + "' data-toggle='modal' data-target='#myModal' name='submitButton' id='btnEdit' value='Edit' />" + "</td>" +  
                        "<td><input type='button' class='btn btn-primary' name='submitButton' id='btnDelete' value='Delete'/> </td></tr>");  
                }  
            },  
            error: function() {  
                alert("Error while Showing update data");  
            }  
        });  
    }  

    and the <g class="gr_ gr_126 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="126" data-gr-id="126">highlight</g> line fetch data from code behind

    [WebMethod]  
       public static Employee[] GetData() //Show the details of the data after insert in HTML Table  
       {  
           var details = new List<Employee>();  
           using (var con = new SqlConnection(Constr))  
           {  
               const string query = "select * from TblUser order by EmpId desc";  
               using (var cmd = new SqlCommand(query, con))  
               {  
                   using (var sda = new SqlDataAdapter())  
                   {  
                       cmd.Connection = con;  
                       sda.SelectCommand = cmd;  
                       TableData.Clear();  
                       sda.Fill(TableData);  
                       details.AddRange(from DataRow dtrow in TableData.Rows  
                           select new Employee  
                           {  
                               EmpId = Convert.ToInt32(dtrow["EmpId"]),  
                               FName = dtrow["Fname"].ToString(),  
                               Email = dtrow["EMail"].ToString(),  
                               HomeMobile = dtrow["Telephone"].ToString(),  
                               OfficeMobile = dtrow["Mobile"].ToString(),  
                               Doj = dtrow["DOJ"].ToString(),  
                               Dob = dtrow["DOB"].ToString()  
                           });  
                   }  
               }  
           }  
           return details.ToArray();  
       }  



     

    Sunday, July 29, 2018 8:03 AM
  • User-1499457942 posted

    Hi

      I am getting this error on below line - Uncaught TypeError: Cannot read property 'length' of undefined

    foror (var i = 0; i < data.d.length; i++)

    Thanks

    Sunday, July 29, 2018 8:20 AM
  • User-1171043462 posted

    Share your code you are using

    Sunday, July 29, 2018 1:06 PM
  • User-893317190 posted

    Hi JagjitSingh ,

    When the error  Uncaught TypeError: Cannot read property 'length' of undefined  occurs ,it’s normally caused by your variable data doesn’t have a property named “d”.


    You could use  F12 developer tool to help you check your data or  use console.log(data) to get more information.


    Press F12  , click the  “Sources” item  and click your aspx page.
        
    Click the number at left to decide which line you want to  put your breakpoint.
          
    Press F5 to reload the page , the  code will stop  where you put your breakpoint.


    You could add another breakpoint. press F8 to skip to the next breakpoint , F10 to go to the next line.
    Move your cursor to your data variable , it will show you detailed information .

    Please check if data has a property named ‘d’.
     
     
    Best regards ,
    Ackerly Xu

    Tuesday, July 31, 2018 9:35 AM