Hi ramco1917,
You need to use if condition.
Please refer below sample.
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<div class="container-fluid">
<asp:PlaceHolder ID="PlaceHolderTable" runat="server"></asp:PlaceHolder>
</div>
Namespaces
C#
using System.Text;
using System.Collections.Generic;
Vb.Net
Imports System.Text
Imports System.Collections.Generic
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
List<Data> items = new List<Data>();
items.Add(new Data { CustomerId = "ALFKI", ContactName = "Alfreds Futterkiste", Status = 0 });
items.Add(new Data { CustomerId = "ANATR", ContactName = "Around the Horn", Status = 1 });
items.Add(new Data { CustomerId = "ANTON", ContactName = "Island Trading", Status = 0 });
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>Status</th><th class='text-center nosort'>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>" + colum.Status + "</td>");
if (colum.Status == 0)
{
htmlTable.Append("<td class='text-center'> <a id='btnAdd' style='pointer-events: none;cursor: default;text-decoration: none;color: #D4D0C8;' class='list-icons-item text-primary-600'><i class='icon-pencil7 mr-1'></i>Add</a></td>");
}
else
{
htmlTable.Append("<td class='text-center'> <a id='btnAdd' style='cursor:pointer;' class='list-icons-item text-primary-600' data-toggle='modal' data-backdrop='static' data-keyboard='false'><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; }
public int Status { get; set; }
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim items As List(Of Data) = New List(Of Data)()
items.Add(New Data With {
.CustomerId = "ALFKI",
.ContactName = "Alfreds Futterkiste",
.Status = 0
})
items.Add(New Data With {
.CustomerId = "ANATR",
.ContactName = "Around the Horn",
.Status = 1
})
items.Add(New Data With {
.CustomerId = "ANTON",
.ContactName = "Island Trading",
.Status = 0
})
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>Status</th><th class='text-center nosort'>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>" & colum.Status & "</td>")
If colum.Status = 0 Then
htmlTable.Append("<td class='text-center'> <a id='btnAdd' style='pointer-events: none;cursor: default;text-decoration: none;color: #D4D0C8;' class='list-icons-item text-primary-600'><i class='icon-pencil7 mr-1'></i>Add</a></td>")
Else
htmlTable.Append("<td class='text-center'> <a id='btnAdd' style='cursor:pointer;' class='list-icons-item text-primary-600' data-toggle='modal' data-backdrop='static' data-keyboard='false'><i class='icon-pencil7 mr-1'></i>Add</a></td>")
End If
htmlTable.Append("</tr>")
Next
htmlTable.Append("</tbody>")
htmlTable.Append("</table>")
PlaceHolderTable.Controls.Add(New Literal With {
.Text = htmlTable.ToString()
})
End If
End Sub
Public Class Data
Public Property CustomerId As String
Public Property ContactName As String
Public Property Status As Integer
End Class
Screenshot