Hi micah,
Refer the below sample and modify your code as per the sample.
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script type="text/javascript">
$(function () {
$("[id*=lnkShowDetails]").click(function () {
var id = $(this).closest('div').find($('[id*=lblcontID]')).text();
$.ajax({
type: "POST",
url: "CS.aspx/GetSavedpost",
data: '{id:"' + id + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response != null) {
$("[id*=txtContactName]").val(response.d[0].ContactName);
$("[id*=txtCity]").val(response.d[0].City);
$("[id*=txtCountry]").val(response.d[0].Country);
$("[id*=txtPhone]").val(response.d[0].Phone);
$('#myModal').modal('show');
}
}
});
return false;
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="Datasaved" runat="server" Width="100%">
<ItemTemplate>
<div class="" style="margin-left: 6px">
<div class="box box box-solid direct-chat direct-chat" style="margin-bottom: 8px">
<div class="well-sm" style="">
<div class=" gamma-container " style="width: 100%; clear: both;">
<asp:Label Text='<%#Eval("ContactName") %>' runat="server" />
</div>
<div class="caption">
<p>
<asp:Label ID="lblpost" runat="server" Text='<%# Eval("Country")%>' Font-Bold="False"
Font-Strikeout="False" ForeColor="#333333" CssClass="" Font-Names="" Font-Size="" />
<asp:Label ID="lblcontID" runat="server" Text='<%#Eval("CustomerId") %>' Style="display: none;" />
</p>
<p>
<asp:LinkButton ID="lnkShowDetails" runat="server" CssClass="btn btn-primary">
<asp:Label ID="Label52" runat="server" Text="$"></asp:Label>
Publish Now
</asp:LinkButton>
</p>
</div>
</div>
</div>
</ItemTemplate>
</asp:DataList>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">
Customer Details</h4>
</div>
<div align="center" class="modal-body">
<table class="table table-responsive">
<tr>
<td>
<b>Contact Name: </b>
<asp:TextBox ID="txtContactName" CssClass="form-control" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<b>City: </b>
<asp:TextBox ID="txtCity" CssClass="form-control" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<b>Country: </b>
<asp:TextBox ID="txtCountry" CssClass="form-control" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<b>Phone: </b>
<asp:TextBox ID="txtPhone" CssClass="form-control" runat="server"></asp:TextBox>
</td>
</tr>
</table>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
</div>
</form>
</body>
</html>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string constr = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT TOP 10 CustomerId,ContactName,City,Country,Phone FROM Customers"))
{
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
Datasaved.DataSource = dt;
Datasaved.DataBind();
}
}
}
}
[WebMethod]
public static List<Customer> GetSavedpost(string id)
{
string constr = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT CustomerId,ContactName,City,Country,Phone FROM Customers WHERE CustomerId = @ID"))
{
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@ID", id);
List<Customer> customers = new List<Customer>();
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
customers.Add(new Customer
{
CustomerId = sdr["CustomerId"].ToString(),
ContactName = sdr["ContactName"].ToString(),
City = sdr["City"].ToString(),
Country = sdr["Country"].ToString(),
Phone = sdr["Phone"].ToString()
});
}
con.Close();
return customers;
}
}
}
public class Customer
{
public string CustomerId { get; set; }
public string ContactName { get; set; }
public string City { get; set; }
public string Country { get; set; }
public string Phone { get; set; }
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim constr As String = ConfigurationManager.ConnectionStrings("DB").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("SELECT TOP 10 CustomerId,ContactName,City,Country,Phone FROM Customers")
cmd.Connection = con
cmd.CommandType = CommandType.Text
Dim da As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
da.Fill(dt)
Datasaved.DataSource = dt
Datasaved.DataBind()
End Using
End Using
End If
End Sub
<WebMethod()> _
Public Shared Function GetSavedpost(id As String) As List(Of Customer)
Dim constr As String = ConfigurationManager.ConnectionStrings("DB").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("SELECT CustomerId,ContactName,City,Country,Phone FROM Customers WHERE CustomerId = @ID")
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("@ID", id)
Dim customers As New List(Of Customer)()
con.Open()
Dim sdr As SqlDataReader = cmd.ExecuteReader()
While sdr.Read()
customers.Add(New Customer() With { _
.CustomerId = sdr("CustomerId").ToString(), _
.ContactName = sdr("ContactName").ToString(), _
.City = sdr("City").ToString(), _
.Country = sdr("Country").ToString(), _
.Phone = sdr("Phone").ToString() _
})
End While
con.Close()
Return customers
End Using
End Using
End Function
Public Class Customer
Public Property CustomerId() As String
Get
Return m_CustomerId
End Get
Set(value As String)
m_CustomerId = value
End Set
End Property
Private m_CustomerId As String
Public Property ContactName() As String
Get
Return m_ContactName
End Get
Set(value As String)
m_ContactName = value
End Set
End Property
Private m_ContactName As String
Public Property City() As String
Get
Return m_City
End Get
Set(value As String)
m_City = value
End Set
End Property
Private m_City As String
Public Property Country() As String
Get
Return m_Country
End Get
Set(value As String)
m_Country = value
End Set
End Property
Private m_Country As String
Public Property Phone() As String
Get
Return m_Phone
End Get
Set(value As String)
m_Phone = value
End Set
End Property
Private m_Phone As String
End Class
Screenshot