Click here to Skip to main content
16,020,459 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Instead of taking gridview, Iam trying to generate a table from backend code c# in asp.net;;

As we see that by taking gridview, we will connect gridview to database and we will get all values present in the data base table;; same like that iam trying to do by generating table from backend code C# and I want to pass query to show data in table from data base sql
Posted
Updated 16-Jul-13 0:26am
v2
Comments
[no name] 16-Jul-13 6:19am    
I m not clear. Improve ur question.

1 solution

It was quite simple in MVC but you feel complex in C#. Because you have to write seperate code for sorting, paging and itemCommand.

For simple table binding, First assign literal/ label
C#
<asp:literal id="ltlTable" runat="server" xmlns:asp="#unknown" />



C#
string strVal= "<table>";
for(int i=0;i<datatable.columns.count;i++)>
{
strVal+="<tr>";
for(int j=0;j&<datatable.rows.count;j++)>
{
strVal+="<td>";
strVal+= dataTable.Rows[i][j].toString();
strVal+="</td>";
}
strVal+="</tr>";
}
strVal+="</table>";

ltlTable.Value = strVal.toString();
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900