0

I want to generate a page in my c# + asp project in visual studio. For connect to my database I use linq-to-SQL, I have 3 collections in my database (Client[id, pseudo, password] , News[id, title, text, idClient], Comment[id, text, idClient, idNews]).

I'd like to display my data like this:

news.title news.text from (client of the news)

[Comment button]

comment1.text from (client of comment)

comment2.text ..

News 2 ...

Exemple:

Hello word with c# blabla... from JohnDoe

[comment]

great post !
from potatoes78

my page:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Labo1
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (((String)Session["connection"]) == "true")
            {
                DataClasses1DataContext dc = new DataClasses1DataContext();
                foreach (News c in dc.News)
                {

                }

            }
        }
    }
}

How to generate my html code ? Should I use javascript or is it possible in C# ?

Thank you before ;)

  • 1
    Have you looked at `ListView`? – Bazzz Oct 20 '15 at 14:34
  • Essentially you are asking for a data binding tutorial for WebForms. There are a lot of tutorials and ways to do this. Have you tried [asp.net's](http://www.asp.net/web-forms) site? It has an entire section with [WebForms tutorials](http://www.asp.net/web-forms) – Panagiotis Kanavos Oct 20 '15 at 14:42

2 Answers2

1

It's on server side, thus you need to write in c#.

Creating a new html file: Creating a file (.htm) in C#

Then you would add more elements you need: https://github.com/Remosy/INFS3204/blob/master/prac3_9P/prac3/Book.aspx.cs

Community
  • 1
  • 1
1

You can generate the html with Response.WriteLine calls, writing out the html. But this is the worst approach to generate html code, better to use webforms or razor, etc.

Dexion
  • 1,101
  • 8
  • 14