Hi ramco1917,
Please refer below sample code.
HTML
<asp:Literal ID="ltTable" runat="server" />
Link
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
Code
CS
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id"), new DataColumn("Name"), new DataColumn("Status") });
dt.Rows.Add(1, "John Hammond", "Active");
dt.Rows.Add(2, "Mudassar Khan", "Blocked");
dt.Rows.Add(3, "Suzanne Mathews", "Active");
dt.Rows.Add(4, "Robert Schidner", "Blocked");
StringBuilder sb = new StringBuilder();
//Table start.
sb.Append("<table>");
//Adding HeaderRow.
sb.Append("<tr>");
foreach (DataColumn column in dt.Columns)
{
sb.Append("<th>" + column.ColumnName + "</th>");
}
sb.Append("</tr>");
//Adding DataRow.
foreach (DataRow row in dt.Rows)
{
sb.Append("<tr>");
foreach (DataColumn column in dt.Columns)
{
if (column.ColumnName == "Status")
{
if (row[column.ColumnName].ToString().ToLower() == "active")
{
sb.Append("<td class='text-center'><a id='btnEdit' class='list-icons-item text-primary-600' data-toggle='modal' data-backdrop='static' data-keyboard='false' data-target='#modal_form_horizontal' onclick='BindData(this);'><i class='icon-pencil7 mr-1 fa fa-edit'></i></a> <a id='btnDel' class='list-icons-item text-danger-600' data-toggle='modal' data-target='#modal_Delete' onclick='BindData(this);'><i style='cursor: pointer' class='icon-bin mr-1 fa fa-trash'></i></a></td>");
}
else
{
sb.Append("<td class='text-center'><a id='btnEdit' class='list-icons-item text-primary-600' data-toggle='modal' data-backdrop='static' data-keyboard='false' data-target='#modal_form_horizontal' onclick='BindData(this);'><i class='icon-pencil7 mr-1 fa fa-edit'></i></a> <a id='btnDel' class='list-icons-item text-danger-600' data-toggle='modal' data-target='#modal_Delete' onclick='BindData(this);'><i style='cursor: not-allowed' class='icon-bin mr-1 fa fa-trash'></i></a></td>");
}
}
else
{
sb.Append("<td>" + row[column.ColumnName].ToString() + "</td>");
}
}
sb.Append("</tr>");
}
//Table end.
sb.Append("</table>");
ltTable.Text = sb.ToString();
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(2) {New DataColumn("Id"), New DataColumn("Name"), New DataColumn("Status")})
dt.Rows.Add(1, "John Hammond", "Active")
dt.Rows.Add(2, "Mudassar Khan", "Blocked")
dt.Rows.Add(3, "Suzanne Mathews", "Active")
dt.Rows.Add(4, "Robert Schidner", "Blocked")
Dim sb As StringBuilder = New StringBuilder()
sb.Append("<table>")
sb.Append("<tr>")
For Each column As DataColumn In dt.Columns
sb.Append("<th>" & column.ColumnName & "</th>")
Next
sb.Append("</tr>")
For Each row As DataRow In dt.Rows
sb.Append("<tr>")
For Each column As DataColumn In dt.Columns
If column.ColumnName = "Status" Then
If row(column.ColumnName).ToString().ToLower() = "active" Then
sb.Append("<td class='text-center'><a id='btnEdit' class='list-icons-item text-primary-600' data-toggle='modal' data-backdrop='static' data-keyboard='false' data-target='#modal_form_horizontal' onclick='BindData(this);'><i class='icon-pencil7 mr-1 fa fa-edit'></i></a> <a id='btnDel' class='list-icons-item text-danger-600' data-toggle='modal' data-target='#modal_Delete' onclick='BindData(this);'><i style='cursor: pointer' class='icon-bin mr-1 fa fa-trash'></i></a></td>")
Else
sb.Append("<td class='text-center'><a id='btnEdit' class='list-icons-item text-primary-600' data-toggle='modal' data-backdrop='static' data-keyboard='false' data-target='#modal_form_horizontal' onclick='BindData(this);'><i class='icon-pencil7 mr-1 fa fa-edit'></i></a> <a id='btnDel' class='list-icons-item text-danger-600' data-toggle='modal' data-target='#modal_Delete' onclick='BindData(this);'><i style='cursor: not-allowed' class='icon-bin mr-1 fa fa-trash'></i></a></td>")
End If
Else
sb.Append("<td>" & row(column.ColumnName).ToString() & "</td>")
End If
Next
sb.Append("</tr>")
Next
sb.Append("</table>")
ltTable.Text = sb.ToString()
End If
End Sub
Screenshot