Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My code as follows

C#
StringBuilder sb = new StringBuilder();
for (int i = 0; i<1; i++)
{
     sb.Append(@"
    <div style="border: 1px solid black; padding: 10px; width: 200px;">
       Hello
    </div>");
 }
    lblErr.Controls.Add(new LiteralControl(sb.ToString()));

When i run the above code and execute output as follows

Hello will be displayed in the output no problem.


But i want to create div using database

my table as follows

id    Link
1     Allcourselist.aspx
2     Accountspage.aspx

i want to create 2 div in the output becuase two records is displaying in the above table.

how to display div using database in asp.net using c@.
Posted
Updated 22-Dec-15 22:21pm
v2
Comments
Sergey Alexandrovich Kryukov 23-Dec-15 1:13am    
This is simply breathtaking...
—SA
VICK 23-Dec-15 2:52am    
Agreed with SA. :(

I think OP haven't heard of any other controls like gridview etc for display of the records.
Kornfeld Eliyahu Peter 23-Dec-15 4:31am    
Search for ASP.NET repeater...
Prasad Avunoori 23-Dec-15 5:03am    
Try gridview

1 solution

First off, as mentioned in the comments, you should first look into the repeater control because it will do this for you automatically. It's very bad form (although sometimes necessary) to be generating html via C# code.

However, if you want to do it the way you are just call the database with a SqlCommand object and return a DataReader.

Then loop through the DataReader results.
 
Share this answer
 

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