C# .NET - How we show record on webpage without using any server control
Asked By ALOK RANJAN on 24-May-12 07:33 AM
hi everyone ,
I have a scenario that I want to show record on web page without using any server control
record should be show just like in gridview through which we can insert another record on page.
please provide me solution.
Thank you
Alok Ranjan
Jitendra Faye replied to ALOK RANJAN on 24-May-12 07:56 AM
For this simply you can convert your DataSource to HTML table.
follow this code-
DataTable yourDataTable = yourDataSet.Tables[0];
for (int i=0; i<yourDataTable.Rows.Count; i++)
{
DataRow currentDataRow = yourDataTable.Rows[i];
TableRow newRow = new TableRow();
for (int j=0; j<currentDataRow.Table.Columns.Count; j++)
{
// Create a Cell (<td>)...
TableCell newCell = new TableCell();
// Set some properties on the cell...
newCell.BackColor = System.Drawing.Color.White;
newCell.ForeColor = System.Drawing.Color.Black;
// Add the text from the DataRow...
newCell.Text = currentDataRow[j].ToString();
// Add the cell to the row...
newRow.Cells.Add(newCell);
}
// Add the row to the table:
this.Table1.Rows.Add(newRow);
}
TRy this and let em know.