Hi Alauddin,
Too replace the id with name you need to make ajax call and replace the id with database record.
Check this example. Now please take its reference and correct your code.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
<table id="12345_AccountInfo">
<tr>
<td id="countries_allowed">
050,344,360,458,702,764
</td>
<td id="currencies_allowed">
1,3,8,13
</td>
<td id="current_outstanding">
288,396.01
</td>
<td id="available_limit">
11,603.99
</td>
</tr>
</table>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
var values = $('#12345_AccountInfo tr').find('td').eq(1).html().trim();
$.ajax({
type: "POST",
url: "Default.aspx/GetDetails",
contentType: "application/json;charset=utf-8",
data: '{ids: "' + values + '" }',
datatype: "json",
success: function (response) {
$('#12345_AccountInfo').find('tr td').eq(1).html(response.d);
}
});
});
</script>
Namespaces
C#
using System.Web.Services;
using System.Data.SqlClient;
using System.Configuration;
VB.Net
Imports System.Data.SqlClient
Imports System.Web.Services
Code
C#
[WebMethod]
public static string GetDetails(string ids)
{
string texts = "";
for (int i = 0; i < ids.Split(',').Length; i++)
{
texts += GetProductName(ids.Split(',')[i]) + ",";
}
return texts.Remove(texts.Length - 1);
}
private static string GetProductName(string id)
{
string name = "";
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
string query = "Select ProductName from Products WHERE ProductId = @Id";
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
cmd.Connection = con;
cmd.Parameters.AddWithValue("@Id", id);
con.Open();
name = Convert.ToString(cmd.ExecuteScalar());
con.Close();
}
return name;
}
VB.Net
<WebMethod()>
Public Shared Function GetDetails(ByVal ids As String) As String
Dim texts As String = ""
For i As Integer = 0 To ids.Split(","c).Length - 1
texts += GetProductName(ids.Split(","c)(i)) & ","
Next
Return texts.Remove(texts.Length - 1)
End Function
Private Shared Function GetProductName(ByVal id As String) As String
Dim name As String = ""
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim query As String = "Select ProductName from Products WHERE ProductId = @Id"
Dim cmd As SqlCommand = New SqlCommand(query)
Using con As SqlConnection = New SqlConnection(conString)
cmd.Connection = con
cmd.Parameters.AddWithValue("@Id", id)
con.Open()
name = Convert.ToString(cmd.ExecuteScalar())
con.Close()
End Using
Return name
End Function
Output
050,344,360,458,702,764 |
Chai,Aniseed Syrup,Northwoods Cranberry Sauce,Konbu |
288,396.01 |
11,603.99 |