Hi,

I want to fill data from database on the webpage. There's no problem with reading the data, filling the menu and so on, but I want to put the text & pictures in the article and this is a real problem :lol: Is there some component (like panel or something) where I can put text with HTML formatting & maybe some pictures?

Thanx,
S

Use the code. This is the whole point of asp.net. You build a webpage on the fly and the asp.net engine will then convert it to html to output to the browser.

Each requirement is different, but you can put any webcontrol on a webpage and give it a value or text (Depending on the control) at run time in page load or other methods. Placeholders, images, textboxes, labels, grids, datalists, the list is endless.

An example would be to give a label some value:

Label1.Text = DataRow1["label1text"].ToString();

Or you can bind in the markup using <%# Eval("columnname", {optional format}) %> tags

Just in case i had your question wrong, the formattiing can be done with css (preferred way) and you can make use of the Literal control and set its text to any html (I will post a tutorial soon on how to write hidden fields on the fly for third party use using literals)

Yes, we definitely don't understand ourselves :) Usually when you want to add text into (for example) panel, you just can write some text, maybe with some hyperlinks etc. in the designer, and then you'll just compile that. But I'm trying to make a dynamic webpage, so I don't want to add any text into panel before compilation. So the whole thing will work this way:

1) I'll design a new webpage in the designer with menus & graphics, but without any text
2) User will call a webpage using the parameter (for example something like this: www.mypage.com/myform.aspx?page=1 )
3) I'll read the requested data from the database (already in HTML) & fill the webpage - here's the problem - panel component don't have a "Text" attribute so I can't add text there on the fly. And I can't use the Label, because this component don't allow me to add any hyperlinks into text, or make a new line whenever I want :(

Notice not everything in the page is loaded from database. Parts like menu and graphics are pre-defined and looks the same on all generated pages.

Ok it is easy and now i understand. The website in my signature is purely made up of code on the fly. Here are some options for you:
Create a panel or placeholder or other such component on your blank page where you want information to go.
On page load read the information from the database and create the relevent controls (labels, images, hyperlinks etc) and add them to the panel.controls. You can apply styles and everything in code just as you would with a normal asp server web control.
The asp.net engine will render the controls as normal. (The only difference you have made between on the fly and using the designer is that the IDE puts the code in the InitializeComponent method where as you have it in page load or some similar method, but the code is the same.
Using panels and other containers renders a <div> tag in html. It also means you can have anything you like in there and will be decided depending on data from the database at run time. Use this if you are not even sure what controls you will need at run time.
If you know what you need but not sure of their values until you get the data at run time then place the controls on there but fill their values from the database when you get the information.

Remember both cases you can apply clientside scripts on the fly at runtime also using the Attributes value for the web control (eg. Mybutton.Attributes.Add("onmouseover", "somejavascriptfunctionname");

Finally (one of my favorite controls) the Literal control lets me put whatever i want in a certain place. I often use this to place an html (as opposed to web server) control on my page in a certain place but am not sure of the control until runtime but know where it wants to go. The literal control will let me put just about any text i like in there so i can put a whole table or just a label or span or anything i like at runtime.
I also use this a lot to post to 3rd party sites where they expect a control with a certain name (if you use a web server control asp.net renames it to make it unique so you have problems). eg paypal will want a hidden control named "amount" for the purchase amount. If you create a label asp.net will rename it in the rendering as ctl001$amount or something similar to ensure it is unique. I need to fill the amount from the database or somewhere so i use a literal with the following code

litHiddenAmount1.Text = @"<input name='amount' type='hidden' value='" + myCart.Total + "' />";

this will render the html markup as if i typed it in the source and no renaming.

Hope these help? Let me know what you need to do (eg unsure of controls until data is present or just need to fill controls with data etc) and i will shed some more light if you need it

Thanks for Literal - it works great, that's exactly what I needed.

I use it a lot :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.