Here I have created sample that will help you out.
HTML
<div>
<asp:PlaceHolder ID="PlaceHolder1" runat="server" />
</div>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = this.GetData();
StringBuilder html = new StringBuilder();
html.Append("<table border = '1'>");
html.Append("<tr>");
html.Append("<th></th>");
foreach (DataColumn column in dt.Columns)
{
html.Append("<th>");
html.Append(column.ColumnName);
html.Append("</th>");
}
html.Append("</tr>");
int count = 0;
foreach (DataRow row in dt.Rows)
{
html.Append("<tr>");
html.Append("<td>");
html.Append("<input id='rb" + count + "' type='radio' name='rb" + count + "' value='rb' /><label for='rb" + count + "'>Select</label>");
html.Append("</td>");
foreach (DataColumn column in dt.Columns)
{
html.Append("<td>");
html.Append(row[column.ColumnName]);
html.Append("</td>");
}
html.Append("</tr>");
count++;
}
html.Append("</table>");
PlaceHolder1.Controls.Add(new Literal { Text = html.ToString() });
}
}
private DataTable GetData()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Country",typeof(string)) });
dt.Rows.Add(1, "John Hammond", "United States");
dt.Rows.Add(2, "Mudassar Khan", "India");
dt.Rows.Add(3, "Suzanne Mathews", "France");
dt.Rows.Add(4, "Robert Schidner", "Russia");
return dt;
}
VB
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Not Me.IsPostBack Then
Dim dt As DataTable = Me.GetData()
Dim html As New StringBuilder()
html.Append("<table border = '1'>")
html.Append("<tr>")
html.Append("<th></th>")
For Each column As DataColumn In dt.Columns
html.Append("<th>")
html.Append(column.ColumnName)
html.Append("</th>")
Next
html.Append("</tr>")
Dim count As Integer = 0
For Each row As DataRow In dt.Rows
html.Append("<tr>")
html.Append("<td>")
html.Append("<input id='rb" + count + "' type='radio' name='rb" + count + "' value='rb' /><label for='rb" + count + "'>Select</label>")
html.Append("</td>")
For Each column As DataColumn In dt.Columns
html.Append("<td>")
html.Append(row(column.ColumnName))
html.Append("</td>")
Next
html.Append("</tr>")
count += 1
Next
html.Append("</table>")
PlaceHolder1.Controls.Add(New Literal() With { _
Key .Text = html.ToString() _
})
End If
End Sub
Private Function GetData() As DataTable
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn(2) {New DataColumn("Id", GetType(Integer)), New DataColumn("Name", GetType(String)), New DataColumn("Country", GetType(String))})
dt.Rows.Add(1, "John Hammond", "United States")
dt.Rows.Add(2, "Mudassar Khan", "India")
dt.Rows.Add(3, "Suzanne Mathews", "France")
dt.Rows.Add(4, "Robert Schidner", "Russia")
Return dt
End Function
Screenshot
