i have follwoing code in jquery

 function CallService3() {

     $.ajax({   
     type: "POST",
     url: "MyService.asmx/Comments",  
//     data: "{ 'loginid': " +"'"+ $("#txt_login").val()+"'" + ", 'pass': " + "'" + $("#txt_pass").val()+"'" + "}",
data: "{}", 
      contentType: "application/json; charset=utf-8",  
      dataType: "json",     
      success: OnSuccess3,
      error: OnError1   
      });     } 

      function OnSuccess3(data, status) {   

      if(data.d.length > 5)
      {
    //  var x = 

   $("#LinkButton1").show();
      }
     //  $("#tbl").append("<tr bgcolor= #FFFF00><th>ID</th><th>NAME</th><th>age</th></tr>");
    // for (var i = 0; i < data.d.length; i++) {
 for (var i = 0; i <= 4; i++) {
 //id of Gridview (*Note name of the columns are CaseSensitive)
 $("#tbl").append("<tr><td>" + i + "</td><td>" + (data.d[i]) +  "</td></tr>");
 }
     // $("#Label1").html(data.d); 
//      $("#tbl").append("<tr bgcolor= #FFFF00><th>ID</th><th>NAME</th><th>age</th></tr>");
//      for (var i = 0; i < data.d.length; i++) {
// //id of Gridview (*Note name of the columns are CaseSensitive)
// $("#tbl").append("<tr><td>" + (data.d[i].id) + "</td><td>" + (data.d[i].name) + "</td><td>" + (data.d[i].age) + "</td></tr>");
// }

       // $("#tbl").fadeOut();
       } 
       function OnError1(request, status, error) { 
    $("#Label1").html(request.statusText);      
       } 

and have following too

      public string[]  Comments()
        {
            List<Details> details = new List<Details>();
            string[] str = new string[6];

            str[0] = "Comment00";
            str[1] = "Comment1";
            str[2] = "Comment2";
            str[3] = "Comment3";
            str[4] = "Comment4";
            str[5] = "Comment5";

            return str;



            //if (loginid == "Admin")
            //{
            //    return "Exist";
            //}

            //return "Not exist";



            //DataTable dtt = new DataTable("Table");

            //dtt.Columns.Add(new DataColumn("id", Type.GetType("System.Int32")));

            //dtt.Columns.Add(new DataColumn("name", Type.GetType("System.String")));

            //dtt.Columns.Add(new DataColumn("age", Type.GetType("System.Int32")));


            //dtt.Rows.Add(1, "A", 12);

            //dtt.Rows.Add(2, "B", 11);

            //dtt.Rows.Add(3, "C", 10);

            //dtt.Rows.Add(4, "D", 09);

            //created a list<> with class Details


            //List<Details> detail = new List<Details>();

            //foreach (DataRow dt_row in dtt.Rows)
            //{

            //    Details usr = new Details();

            //    usr.id = Convert.ToInt32(dt_row["id"]);

            //    usr.name = dt_row["name"].ToString();

            //    usr.age = Convert.ToInt32(dt_row["age"]);

            //    detail.Add(usr);

            //}

           // return detail.ToArray();  // returning records of array


        }

it bind html table with data return by web method ..now i need to show two things in it at the same time ..for loop counter i.e i (0,1,2,...) and <a href >data</a> for each row ..is there any way to do so

Recommended Answers

All 5 Replies

Member Avatar for LastMitch

it bind html table with data return by web method ..now i need to show two things in it at the same time ..for loop counter i.e i (0,1,2,...) and <a href >data</a> for each row ..is there any way to do so

You mean row not cell?

Why did you comment your code like that?

Even though it's in ASP.net you don't have to comment code that is related jQuery?

It's pretty normal to have both languages but it seems you took time doing that it?

an extra cell or columns required

code was un-necessary that's why i commented

let me put my problem in quite brief manner

i have ajax/json method (web method) which binds html table in following way (let me share piece of code)

1.
for (var i = 0; i < data.d.length; i++) {


$(

"#tbl").append("<tr><td>" + (data.d[i].id) + "</td><td>" + (data.d[i].name) + "</td><td>" + (data.d[i].age) + "</td></tr>");
Member Avatar for LastMitch

code was un-necessary that's why i commented

I'm not sure why you post this code which has nothing to do with your jQuery code:

I'm assuming it's JSP or some sort of Java you are using with ASP.net:

public string[] Comments(){
List<Details> details = new List<Details>();
string[] str = new string[6];
str[0] = "Comment00";
str[1] = "Comment1";
str[2] = "Comment2";
str[3] = "Comment3";
str[4] = "Comment4";
str[5] = "Comment5";
return str;

This code here doesn't really work because you comment this:

List<Details> details = new List<Details>();

on line 46?

What do you want to do with this code here which is line 30 and line 32 (you comment this code from above and now this is the main issue?):

for (var i = 0; i < data.d.length; i++) {
$("#tbl").append("<tr><td>" + (data.d[i].id) + "</td><td>" + (data.d[i].name) + "</td><td>" + (data.d[i].age) + "</td></tr>");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.