to call C# array type webmethod.
Hide Copy Code
<script type="text/javascript">
$(document).ready(function () { $("#tblCustomers tbody tr").remove(); $.ajax({ type: "POST",
url: "GetDataByJquery.aspx/GetMessages",
data: '{roomId: "' + $("[id$=lblRoomId]").html() + '" }', contentType: "application/json; charset=utf-8",
dataType: "json", success: function (data) { response($.map(data.d, function (item) { var rows = "<tr>" + "<td class='customertd'>" + item.Username + "</td>"
+ "<td class='customertd'>" + item.Sex + "</td>"
+ "<td class='customertd'>" + item.Text + "</td>"
+ "<td class='customertd'>" + item.TimeStamp + "</td>"
+ "<td class='customertd'>" + item.UserID + "</td>"
+ "</tr>";
$('#tblCustomers tbody').append(rows); })) },
failure: function (response) { alert(response.d); } }); });
</script>
Got data from sqlserver and reterning in array.
Hide Expand
Copy Code
Copy Codepublic static Messages[] GetMessages(string roomId)
{ Listmessages = new List ();
string strConnString = ConfigurationManager.ConnectionStrings["LinqChatConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
{ using (SqlDataAdapter sda = new SqlDataAdapter()) { string query = "[Get_Messages]";
SqlCommand cmd = new SqlCommand(query); cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@roomId", roomId);
cmd.Connection = con;
sda.SelectCommand = cmd;
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read()) { Messages message = new Messages(); message.Username = reader.GetString(0); message.Sex = reader.GetString(1); message.Text = reader.GetString(2); message.TimeStamp = reader.GetDateTime(3); message.UserID = reader.GetInt32(4); messages.Add(message); } } }
return messages.ToArray(); } but I can't display the data..so how to display it?

Dawood AbbasPosted Aug 27, 2015, 3:10 AM
Manas MohapatraPosted Aug 27, 2015, 2:51 AM
Dawood AbbasPosted Aug 27, 2015, 2:30 AM
Manas MohapatraPosted Aug 27, 2015, 2:24 AM
Dawood AbbasPosted Aug 27, 2015, 2:13 AM
Manas MohapatraPosted Aug 27, 2015, 1:00 AM