Hi ramco1917,
Please refer below sample.
HTML
<asp:Label ID="lblMessage" runat="server" />
Namespaces
C#
using System.Text;
using System.Collections.Generic;
VB.Net
Imports System.Collections.Generic
Imports System.Text
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
List<Training> Result = new List<Training>();
Result.Add(new Training
{
TrainingID = 1,
EmpName = "Test 1",
TrainingNumber = "123",
TrainingTypeMaster = new TrainingType { Description = "ASP.Net" }
});
Result.Add(new Training
{
TrainingID = 2,
EmpName = "Test 2",
TrainingNumber = "125",
LocationMaster = new Location { LocationName = "Mumbai" }
});
StringBuilder htmlTable = new StringBuilder();
htmlTable.Append("<table>");
foreach (var colum in Result)
{
string EmpName = colum.EmpName;
htmlTable.Append("<tr>");
htmlTable.Append("<td style='display:none'>" + colum.TrainingID + "</td>");
htmlTable.Append("<td>" + colum.TrainingNumber + "</td>");
if (colum.TrainingTypeMaster != null)
{
htmlTable.Append(colum.TrainingTypeMaster.Description != null ? "<td>" + colum.TrainingTypeMaster.Description + "</td>" : "<td></td>");
}
else
{
htmlTable.Append("<td></td>");
}
if (colum.LocationMaster != null)
{
htmlTable.Append(colum.LocationMaster.LocationName != null ? "<td>" + colum.LocationMaster.LocationName : "</td>" + "<td></td>");
}
else
{
htmlTable.Append("<td></td>");
}
htmlTable.Append("<td>" + EmpName + "</td>");
htmlTable.Append("<td class='text-center'><a id='btnEdit' style='cursor:pointer;' class='list-icons-item text-primary-600' title='Edit' href='NewTraining.aspx?val=" + colum.TrainingID + "'><i class='fas fa-pencil'></i> </a>" + "</td>");
htmlTable.Append("</tr>");
}
htmlTable.Append("</table>");
lblMessage.Text = htmlTable.ToString();
}
public class Training
{
public int TrainingID { get; set; }
public string EmpName { get; set; }
public string TrainingNumber { get; set; }
public TrainingType TrainingTypeMaster { get; set; }
public Location LocationMaster { get; set; }
}
public class TrainingType
{
public string Description { get; set; }
}
public class Location
{
public string LocationName { get; set; }
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim Result As List(Of Training) = New List(Of Training)()
Result.Add(New Training With {
.TrainingID = 1,
.EmpName = "Test 1",
.TrainingNumber = "123",
.TrainingTypeMaster = New TrainingType With {
.Description = "ASP.Net"
}
})
Result.Add(New Training With {
.TrainingID = 2,
.EmpName = "Test 2",
.TrainingNumber = "125",
.LocationMaster = New Location With {
.LocationName = "Mumbai"
}
})
Dim htmlTable As StringBuilder = New StringBuilder()
htmlTable.Append("<table>")
For Each colum In Result
Dim EmpName As String = colum.EmpName
htmlTable.Append("<tr>")
htmlTable.Append("<td style='display:none'>" & colum.TrainingID & "</td>")
htmlTable.Append("<td>" & colum.TrainingNumber & "</td>")
If colum.TrainingTypeMaster IsNot Nothing Then
htmlTable.Append(If(colum.TrainingTypeMaster.Description IsNot Nothing, "<td>" & colum.TrainingTypeMaster.Description & "</td>", "<td></td>"))
Else
htmlTable.Append("<td></td>")
End If
If colum.LocationMaster IsNot Nothing Then
htmlTable.Append(If(colum.LocationMaster.LocationName IsNot Nothing, "<td>" & colum.LocationMaster.LocationName, "</td>" & "<td></td>"))
Else
htmlTable.Append("<td></td>")
End If
htmlTable.Append("<td>" & EmpName & "</td>")
htmlTable.Append("<td class='text-center'><a id='btnEdit' style='cursor:pointer;' class='list-icons-item text-primary-600' title='Edit' href='NewTraining.aspx?val=" & colum.TrainingID & "'><i class='fas fa-pencil'></i> </a>" & "</td>")
htmlTable.Append("</tr>")
Next
htmlTable.Append("</table>")
lblMessage.Text = htmlTable.ToString()
End Sub
Public Class Training
Public Property TrainingID As Integer
Public Property EmpName As String
Public Property TrainingNumber As String
Public Property TrainingTypeMaster As TrainingType
Public Property LocationMaster As Location
End Class
Public Class TrainingType
Public Property Description As String
End Class
Public Class Location
Public Property LocationName As String
End Class
Screenshot