shekhar patel shekhar patel - 3 months ago 15
Ajax Question

Rating Using Ajax Control Specified Cast not working

Onsucess Function it fetch data from database and store in xml format, but while i use rating control it gives specified cast is not vallid.
I think my rating value is not converted in int format



function OnSuccess(response) {
debugger;
//data in XML Format
var data = response.d;
var xmlDoc = $.parseXML(data);
var xml = $(xmlDoc);
var customers = xml.find("Table");
//var repeatColumns = parseInt("<%=dlCustomers.RepeatColumns == 0 ? 1 : dlCustomers.RepeatColumns %>");
var repeatColumns = 1;
//find total record or row
var rowCount = Math.ceil(customers.length / repeatColumns);
var i = 0;
while (i < repeatColumns * rowCount) {
//dlcustomer is my datalist id, bind value in it by finding the class
var row = $("[id*=dlCustomers] tr").eq(0).clone(true);
for (var j = 0; j < repeatColumns; j++) {
var customer = $(customers[i]);
if (customer.length == 0) {

} else {


$(".Rating", row).eq(j).html(customer.find("Rating").text());
$(".Date", row).eq(j).html(customer.find("Date").text());
$(".Comment", row).eq(j).html(customer.find("Comment").text());
$(".TopicName", row).eq(j).html(customer.find("TopicName").text());

}
i++;
}
$("[id*=dlCustomers]").append(row);
}
$("[id*=dlCustomers] tr").eq(0).remove();
$("[id*=dlCustomers]").show();
}




Answer

Here i Am giving a function for your solution just try to replace with following code .

function BindData(rating, topic) {
    debugger;
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "ReviewPage.aspx/BindDatatable",
        data: JSON.stringify({Rating:rating, Topic:topic}),
        dataType: "json",
        success: function (data) {


            $('#img').empty();
            $('#theList').empty();



            //     var id = "img" ;
            //   var rating = v;
            for (i = 0; i < i < data.d.length; i++) {
                // var id = "img" + data.d[i].RatingStar;
                rating = data.d[i].Rating;
              
                getImgRating(rating)
                function getImgRating(rating) {

                    debugger;
                    for (j = 0; j < rating; j++) {
                        var img = $('<img id= "star">');
                        img.attr("src", "Images/starselects.png");
                        img.appendTo("#img");

                        // td.append(img);
                    }
                    if (rating != 5) {
                        for (k = rating; k < 5; k++) {
                            var img = $('<img id= "star">');
                            img.attr("src", "Images/star-deselect.png");
                            img.appendTo("#img");
                            //   $("#tblreview").append("<tr><td id=" + img + "></tr></td>")
                        }
                    }
                    $("#img").append("<ul><li style='list-style-type:none ; width:60px;font-weight:Bold'>" + data.d[i].Topic + "</ul></li>" + "<ul><li style=' list-style-type:none ; width:40px' >" + data.d[i].Comment + "</ul></li>" + "<ul><li style='list-style-type:none ; width:100px'>" + data.d[i].Date + "</ul></li>");

              
                }
            }

        
            },
            
           
        error: function (result) {
            alert("Error");
        }
    });
}