Hi ramco1917,
Please refer below sample.
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<div class="container-fluid">
<asp:PlaceHolder ID="PlaceHolderTable" runat="server"></asp:PlaceHolder>
</div>
<asp:Button ID="btnDummy" Text="" runat="server" Style="display: none;" OnClick="Edit" />
<asp:HiddenField ID="hfUrl" runat="server" />
<script type="text/javascript">
$('body').on('click', '#btnEdit', function () {
$('[Id$=hfUrl]').val($(this).data('href'));
$('[Id$=btnDummy]').trigger('click');
});
</script>
Namespace
C#
using System.Text;
VB.Net
Imports System.Text
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
List<Data> items = new List<Data>();
items.Add(new Data { CustomerId = "ALFKI", ContactName = "Alfreds Futterkiste" });
items.Add(new Data { CustomerId = "ANATR", ContactName = "Around the Horn" });
items.Add(new Data { CustomerId = "ANTON", ContactName = "Island Trading" });
StringBuilder htmlTable = new StringBuilder();
htmlTable.Append("<table class='table table-bordered table-hover datatable-highlight' id='tbldata'>");
htmlTable.Append("<thead><tr><th>Customer Id</th><th>Name</th><th class='text-center'>Edit</th><th class='text-center'>Add</th></tr></thead>");
htmlTable.Append("<tbody>");
foreach (var colum in items)
{
htmlTable.Append("<tr>");
htmlTable.Append("<td>" + colum.CustomerId + "</td>");
htmlTable.Append("<td>" + colum.ContactName + "</td>");
htmlTable.Append("<td class='text-center'><a id='btnEdit' style='cursor:pointer; class='list-icons-item text-primary-600' title='Edit' data-href='NewTraining.aspx?val="
+ colum.CustomerId.ToString() + "'><i class='icon-pencil7 mr-1'></i>Edit</a></td> <td class='text-center'><a id='btnAdd' style='cursor:pointer;' class='list-icons-item text-primary-600' title='Add' href='Nominee.aspx?val="
+ colum.CustomerId.ToString() + "'><i class='icon-pencil7 mr-1'></i>Add</a></td>");
htmlTable.Append("</tr>");
}
htmlTable.Append("</tbody>");
htmlTable.Append("</table>");
PlaceHolderTable.Controls.Add(new Literal { Text = htmlTable.ToString() });
}
public class Data
{
public string CustomerId { get; set; }
public string ContactName { get; set; }
}
protected void Edit(object sender, EventArgs e)
{
string url = hfUrl.Value;
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + url + "')", true);
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim items As List(Of Data) = New List(Of Data)()
items.Add(New Data With {
.CustomerId = "ALFKI",
.ContactName = "Alfreds Futterkiste"
})
items.Add(New Data With {
.CustomerId = "ANATR",
.ContactName = "Around the Horn"
})
items.Add(New Data With {
.CustomerId = "ANTON",
.ContactName = "Island Trading"
})
Dim htmlTable As StringBuilder = New StringBuilder()
htmlTable.Append("<table class='table table-bordered table-hover datatable-highlight' id='tbldata'>")
htmlTable.Append("<thead><tr><th>Customer Id</th><th>Name</th><th class='text-center'>Edit</th><th class='text-center'>Add</th></tr></thead>")
htmlTable.Append("<tbody>")
For Each colum In items
htmlTable.Append("<tr>")
htmlTable.Append("<td>" & colum.CustomerId & "</td>")
htmlTable.Append("<td>" & colum.ContactName & "</td>")
htmlTable.Append("<td class='text-center'><a id='btnEdit' style='cursor:pointer; class='list-icons-item text-primary-600' title='Edit' data-href='NewTraining.aspx?val=" &
colum.CustomerId.ToString() & "'><i class='icon-pencil7 mr-1'></i>Edit</a></td> <td class='text-center'><a id='btnAdd' style='cursor:pointer;' class='list-icons-item text-primary-600' title='Add' href='Nominee.aspx?val=" +
colum.CustomerId.ToString() & "'><i class='icon-pencil7 mr-1'></i>Add</a></td>")
htmlTable.Append("</tr>")
Next
htmlTable.Append("</tbody>")
htmlTable.Append("</table>")
PlaceHolderTable.Controls.Add(New Literal With {
.Text = htmlTable.ToString()
})
End Sub
Public Class Data
Public Property CustomerId As String
Public Property ContactName As String
End Class
Protected Sub Edit(ByVal sender As Object, ByVal e As EventArgs)
Dim url As String = hfUrl.Value
ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('" & url & "')", True)
End Sub
Screenshot