473,413 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

ASP.NET Create HTML page on the fly based on dB table

Hi all
I am newbie to ASP.NET am facing this problem.

I search the web but I can't seem to find an example of code where I can generate an html file on the fly.

I am reading through a table tblData and perform some calculations, if the calculations fails then I insert the record to a seperate table tblErrors.

At the end of the caculation, I want to read the tblErrors and output its contents [fields] to the HTML page for the users to see.

I would appreciate if somebody provide me a step by step on how to get achieve this. I am doing some reading by maybe I am not understanding them properyl.

Please assist.

Thanks so much
Feb 21 '08 #1
6 5154
jeffstl
432 Expert 256MB
Hi.
I recently started learning ASP.NET as well.

You are correct, there is no more "response.write" type of output with .NET. Everything with ASP.NET is about objects\controls.

The good news is that if you can get the data you want to display through an SQL query you can display it as you describe in the datagrid control fairly easily.

Assuming you have your database connection up and your sql executing on a page load, or button click event, you can do something like this.

Expand|Select|Wrap|Line Numbers
  1.     'PLACE THIS CODE IN A SUB PAGE_LOAD, OR BUTTON CLICK
  2.     dbconn.Open()
  3.  
  4.  
  5.     sql="SELECT * FROM TblErrors"
  6.     dbcomm=New OleDbCommand(sql,dbconn)
  7.     dbread=dbcomm.ExecuteReader()
  8.     MyErrorGrid.DataSource=dbread
  9.     MyErrorGrid.DataBind()
  10.  
  11.     dbread.close
  12.     dbconn.close
  13.  
  14.     'PLACE THIS CODE IN YOUR HTML DESIGN
  15. <asp:DataGrid id="MyErrorGrid" runat="server"
  16.     AutoGenerateColumns="False" CellPadding="3"
  17.     HeaderStyle-BackColor="#A4A6CF"
  18.     HeaderStyle-ForeColor="000033"
  19.     HeaderStyle-HorizontalAlign="Left"
  20.     HeaderStyle-Font-Bold="True"
  21.     BackColor="#eeeeee" Width="50%"
  22.     HorizontalAlign="Left"
  23.     Font-Bold="True" Font-Name="Tahoma"
  24.     Font-Size="10pt">
  25.  
  26.     <AlternatingItemStyle BackColor="White" />
  27.  
  28.     <Columns>
  29.         <asp:BoundColumn HeaderText="Error Data1" DataField="data_field1" />
  30.         <asp:BoundColumn HeaderText="Error Data2" DataField="data_field2" />                       
  31.     </Columns>        
  32. </asp:DataGrid>
  33.  
Feb 21 '08 #2
jeffstl
432 Expert 256MB
Guess I should point out too, that before the

dbconn.open you should have something that sets up your connection string..I use access currently so it looks like this. Where default_DB_Path was setup previously as my path.

Also know that there are other neat ways to use connection strings in .NET such as in the web.config file.

Expand|Select|Wrap|Line Numbers
  1. dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & default_DB_Path & ";")
  2.  
  3.  
Feb 21 '08 #3
Thanks jeffstl
Much appreciated. It works and truly helps
Feb 22 '08 #4
pozze
8
Is it hard to modify this exmple to retrieve images sucessfuly stored in the db and display them in the datagrid as well?
Feb 24 '08 #5
jeffstl
432 Expert 256MB
Unless you are storing the full path I think what you would want to do is load the path and the value from the database into a asp.net literal control once you have the data.

Where DBReader is a set of data from a read.
Like this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. 'place in code behind (sub_load, etc)
  3. myimage.Text = "<img src=../databases/images/" & DBReader("imagecolumn") & " height=80 width=80 align=center>"
  4.  
  5.  
  6. 'place in HTML design
  7. <asp:Literal id="myimage" runat="server" />
  8.  
  9.  
Feb 25 '08 #6
pozze
8
thanks for the reply, but i have figured it out myself :)

Unless you are storing the full path I think what you would want to do is load the path and the value from the database into a asp.net literal control once you have the data.

Where DBReader is a set of data from a read.
Like this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. 'place in code behind (sub_load, etc)
  3. myimage.Text = "<img src=../databases/images/" & DBReader("imagecolumn") & " height=80 width=80 align=center>"
  4.  
  5.  
  6. 'place in HTML design
  7. <asp:Literal id="myimage" runat="server" />
  8.  
  9.  
Feb 25 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: dawnunder | last post by:
eg. Someone fills out 3 fields. (There will be more but this is just to give you an idea) 1. Country? 2. State? 3. City I want this script to generate a web page and list the people by
3
by: Kiyomi | last post by:
Hello, I create a Table1 dynamically at run time, and at the same time, I would like to create LinkButton controls, also dynamically, and insert them into each line in my Table1. I would...
8
by: RC | last post by:
The following code works well to create an html file that has a row for each row in my table. My Access 2002 database has a tabel with 3 columns labeled, Model, CD and Hard Drive (HD). Any...
5
by: Andrew | last post by:
Hi, friends, In ASP, we use obj = CreateObject("com.dll") obj.GetHTMLText(inVal, outHTMLTxt1, outHTMLTxt2) to get different HTML strings based on input values. Then, we insert them into...
2
by: Jake Barnes | last post by:
Using javascript closures to create singletons to ensure the survival of a reference to an HTML block when removeChild() may remove the last reference to the block and thus destory the block is...
2
by: Geary | last post by:
I am porting my first traditional app to a web-based app using VS2005 and ASP.NET 2.0. I have a page that will replace a data entry form. To have complete control of layout, I want to use a table...
1
by: since | last post by:
I figured I would post my solution to the following. Resizable column tables. Search and replace values in a table. (IE only) Scrollable tables. Sortable tables. It is based on a lot...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
2
by: nja2222 | last post by:
I would like to create a page for my clients to login and check for updates on their accounts. Then I would like to create a page where my employees can login and make updates, specifically new file...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.