Hi kavithav,
Please refer below sample.
Note: For this sample i have used temporary DataTable. For more details refer Dynamically create DataTable and bind to GridView in ASP.Net.
HTML
<asp:Label ID="lblDetails" runat="server" Text='<%# Eval("Details") %>' ></asp:Label>
NameSpace
C#
using System.Data;
VB
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.GridBind();
}
}
private void GridBind()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] {
new DataColumn("col1"),
new DataColumn("col2"),
new DataColumn("col3"),
});
dt.Rows.Add("c1 c1", "c3", "c4");
dt.Rows.Add("a^b", "c", "d");
dt.Rows.Add("e^f", "c", "d");
dt.Rows.Add("g^h", "c", "d");
string html = "<table border='1'>";
for (int row = 0; row < dt.Rows.Count; row++)
{
html += "<tr>";
DataRow dr = dt.Rows[row];
for (int column = 0; column < dt.Columns.Count; column++)
{
if (dr[column].ToString().Split(' ').Length > 1)
{
html += "<td>" + dr[column].ToString().Split(' ')[0] + "</td>";
html += "<td>" + dr[column].ToString().Split(' ')[1] + "</td>";
}
else if (dr[column].ToString().Split('^').Length > 1)
{
html += "<td>" + dr[column].ToString().Split('^')[0] + "</td>";
html += "<td>" + dr[column].ToString().Split('^')[1] + "</td>";
}
else
{
html += "<td>" + dr[column].ToString() + "</td>";
}
}
html += "</tr>";
}
html += "</table>";
Label lblDetails = this.FindControl("lblDetails") as Label;
lblDetails.Text = string.Copy(html);
}
VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.GridBind()
End If
End Sub
Private Sub GridBind()
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(2) {New DataColumn("col1"), New DataColumn("col2"), New DataColumn("col3")})
dt.Rows.Add("c1 c1", "c3", "c4")
dt.Rows.Add("a^b", "c", "d")
dt.Rows.Add("e^f", "c", "d")
dt.Rows.Add("g^h", "c", "d")
Dim html As String = "<table border='1'>"
For row As Integer = 0 To dt.Rows.Count - 1
html += "<tr>"
Dim dr As DataRow = dt.Rows(row)
For column As Integer = 0 To dt.Columns.Count - 1
If dr(column).ToString().Split(" "c).Length > 1 Then
html += "<td>" & dr(column).ToString().Split(" "c)(0) & "</td>"
html += "<td>" & dr(column).ToString().Split(" "c)(1) & "</td>"
ElseIf dr(column).ToString().Split("^"c).Length > 1 Then
html += "<td>" & dr(column).ToString().Split("^"c)(0) & "</td>"
html += "<td>" & dr(column).ToString().Split("^"c)(1) & "</td>"
Else
html += "<td>" & dr(column).ToString() & "</td>"
End If
Next
html += "</tr>"
Next
html += "</table>"
Dim lblDetails As Label = TryCast(Me.FindControl("lblDetails"), Label)
lblDetails.Text = String.Copy(html)
End Sub
Screenshot