Hi @Aypn CNN,
You need to put the Repeater control inside an HTML DIV because the Repeater control doesn't render itself, so you can't access it via JavaScript or jQuery using the client ID.
Here is the changed code:
<div id="dvTests">
<asp:Repeater ID="rptUserinfo" runat="server">
//.......
</asp:Repeater>
</div>
$('#dvTests table').append('<tr><td>' + hoquery + '</td><td>' + branchreply + '</td></tr>');
You also need to make sure you get the correct json, which you can check with alert(result);
The following is an example of my test using test data, you can refer to:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-3.4.1.min.js"></script>
<script type="text/javascript">
$(function () {
$.ajax({
type: "POST",
url: "WebForm3.aspx/getQryInfo",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var result = JSON.parse(response.d);
alert(result);
$.each(result, function (i, item) {
var hoquery = item.HOQueries;
var branchreply = item.BranchResponse;
$('#dvTests table').append('<tr><td>' + hoquery + '</td><td>' + branchreply + '</td></tr>');
});
},
error: function (data, ex) { }
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="dvTests">
<asp:Repeater ID="rptUserinfo" runat="server">
<HeaderTemplate>
<table id="tblQryInfo" class="table">
<tr>
<th id="thHO" runat="server">HO Query</th>
<th id="thBrReply" runat="server">BranchReply</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="font-size: 10px;">
<td id="tdho" runat="server"><%#Eval("HOQueries") %></td>
<td id="tdbr" runat="server"><%#Eval("BranchResponse") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim tests As List(Of Test) = New List(Of Test)()
tests.Add(New Test())
rptUserinfo.DataSource = tests
rptUserinfo.DataBind()
End Sub
<WebMethod>
Public Shared Function getQryInfo() As String
Dim p As List(Of Test) = New List(Of Test)()
Dim p1 As Test = New Test()
p1.Id = "1"
p1.HOQueries = "a"
p1.BranchResponse = "a"
Dim p2 As Test = New Test()
p2.Id = "2"
p2.HOQueries = "b"
p2.BranchResponse = "b"
p.Add(p1)
p.Add(p2)
Dim json As String = JsonConvert.SerializeObject(p)
Return json
End Function
Public Class Test
Public Property Id As String
Public Property HOQueries As String
Public Property BranchResponse As String
End Class
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.