Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Howto:HTML template which needs to be filled with data from a data

Reply
Thread Tools

Howto:HTML template which needs to be filled with data from a data

 
 
=?Utf-8?B?VmxhZHk=?=
Guest
Posts: n/a
 
      10-04-2004
Hello. I recently built an ASP.NET "financial" application. I got to the
point where I have a HTML template (a contract) which needs to be filled with
various data from the database. I put a "generate contract" button on my ASPX
page, but I totally lack ideas of how to put the data in the correct places
in the html file. I was recommended (actually "do like this" from my boss) to
enclose the variable name like this {variable_name} in the html, and he said
that there are some functions to assign the value to the variable but how???
So the question is: how can I place the data that I gather from the database
inside the html file using only asp.net, without any report generation tool
(click the button and there you go: window with the contract filled)? A
little more elaborated example would be highly appreciated as this is my
first ASP.NET app.
 
Reply With Quote
 
 
 
 
=?Utf-8?B?S2VuIENveCBbTWljcm9zb2Z0IE1WUF0=?=
Guest
Posts: n/a
 
      10-04-2004
Hi Vlady,

Can you insert label controls where the data needs to go? That way you can
pick up the data and insert it into the labels, including calculations.
There's a quick example below. Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]
Toronto

<%@ Page Language="VB" %>
<script runat="server">

' Insert page code here
'
Sub Page_Load
' initialize here
if not ispostback then
label1.text= "no"
label2.text= "0"
end if
End sub

Sub Button1_Click(sender As Object, e As EventArgs)
if textbox1.text <> "" and isnumeric(textbox1.text) then
' Get your values from the database
label1.text= textbox1.text
Label2.text=(3.25 * cdec(textbox1.text)).tostring("C")
else
label1.text= "no"
label2.text= "0"
end if
End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button id="Button1" onclick="Button1_Click" runat="server"
Text="Order"></asp:Button>
</p>
<p>
You have ordered <asp:Label id="Label1"
runat="server"></asp:Label> Widgets.
The value of the widgets is <asp:Label id="Label2"
runat="server"></asp:Label>.
</p>
</form>
</body>
</html>


"Vlady" wrote:

> Hello. I recently built an ASP.NET "financial" application. I got to the
> point where I have a HTML template (a contract) which needs to be filled with
> various data from the database. I put a "generate contract" button on my ASPX
> page, but I totally lack ideas of how to put the data in the correct places
> in the html file. I was recommended (actually "do like this" from my boss) to
> enclose the variable name like this {variable_name} in the html, and he said
> that there are some functions to assign the value to the variable but how???
> So the question is: how can I place the data that I gather from the database
> inside the html file using only asp.net, without any report generation tool
> (click the button and there you go: window with the contract filled)? A
> little more elaborated example would be highly appreciated as this is my
> first ASP.NET app.

 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      10-04-2004
To make sure i understand the question, let me rephrase it. You are
wondering how to put values from some data structure (say a dataset) into a
web page. I take it the point to your question is that you don't want to
manually have to do:

txtEmail.Text = datatable.rows[0]["Email"];

for some 100 fields?

In asp.net 2.0 there'll be a DetailsView to help automate this otherwise
highly manual process
(http://msdn.microsoft.com/asp.net/wh...library/en-us/
dnvs05/html/grddetview.asp#grddetview_topic5)

Currently, you can look for a similar controls for 1.0...Your only other
alternative is to do something like:

<table>
<tr>
<td>First Name</td>
<td><asp:textbox runat="server" id="firstName" /></td>
</tr>
<tr>
<td>LastName</td>
<td><asp:textbox runat="server" id="lastName" /></td>
</tr>
</table>

then in codebehind:

foeach (DataColumn column in datatable.Columns){
Control c = page.FindControl(c.ColumnName)
if (c != null){
if (typeof(c) == TextBox){
((TextBox)c).Text = datatable.rows[0][column];
}else if (typeof(c) == RadioButtonList){
....
}
}
}

anyways, just some rough ideas...

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/


"Vlady" <> wrote in message
news:94946B6C-3826-432D-BE45-...
> Hello. I recently built an ASP.NET "financial" application. I got to the
> point where I have a HTML template (a contract) which needs to be filled

with
> various data from the database. I put a "generate contract" button on my

ASPX
> page, but I totally lack ideas of how to put the data in the correct

places
> in the html file. I was recommended (actually "do like this" from my boss)

to
> enclose the variable name like this {variable_name} in the html, and he

said
> that there are some functions to assign the value to the variable but

how???
> So the question is: how can I place the data that I gather from the

database
> inside the html file using only asp.net, without any report generation

tool
> (click the button and there you go: window with the contract filled)? A
> little more elaborated example would be highly appreciated as this is my
> first ASP.NET app.



 
Reply With Quote
 
=?Utf-8?B?VmxhZHk=?=
Guest
Posts: n/a
 
      10-05-2004
In my contract details page I have a GENERATE CONTRACT button. What does it
do? It retrieves the coresponding row from contracts table by ID, and the
products child rows (nevermind this last one). After that I presume a
Server.Transfer("blablablafile.htm") to the completed page with the missing
fields that I got from the table. But the problem is that in that html (not
aspx) there has to be no scripting code as I got it from my boss. It could
have been easily resolved by use of Session in an aspx page but again "the
boss" said that in html should be inserts like {variable_name}. Let me know
if it is necessary to further explain myself, as I am a little annoyed by
this little thingie.

"Karl Seguin" wrote:

> To make sure i understand the question, let me rephrase it. You are
> wondering how to put values from some data structure (say a dataset) into a
> web page. I take it the point to your question is that you don't want to
> manually have to do:
>
> txtEmail.Text = datatable.rows[0]["Email"];
>
> for some 100 fields?
>
> In asp.net 2.0 there'll be a DetailsView to help automate this otherwise
> highly manual process
> (http://msdn.microsoft.com/asp.net/wh...library/en-us/
> dnvs05/html/grddetview.asp#grddetview_topic5)
>
> Currently, you can look for a similar controls for 1.0...Your only other
> alternative is to do something like:
>
> <table>
> <tr>
> <td>First Name</td>
> <td><asp:textbox runat="server" id="firstName" /></td>
> </tr>
> <tr>
> <td>LastName</td>
> <td><asp:textbox runat="server" id="lastName" /></td>
> </tr>
> </table>
>
> then in codebehind:
>
> foeach (DataColumn column in datatable.Columns){
> Control c = page.FindControl(c.ColumnName)
> if (c != null){
> if (typeof(c) == TextBox){
> ((TextBox)c).Text = datatable.rows[0][column];
> }else if (typeof(c) == RadioButtonList){
> ....
> }
> }
> }
>
> anyways, just some rough ideas...
>
> Karl
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
>
> "Vlady" <> wrote in message
> news:94946B6C-3826-432D-BE45-...
> > Hello. I recently built an ASP.NET "financial" application. I got to the
> > point where I have a HTML template (a contract) which needs to be filled

> with
> > various data from the database. I put a "generate contract" button on my

> ASPX
> > page, but I totally lack ideas of how to put the data in the correct

> places
> > in the html file. I was recommended (actually "do like this" from my boss)

> to
> > enclose the variable name like this {variable_name} in the html, and he

> said
> > that there are some functions to assign the value to the variable but

> how???
> > So the question is: how can I place the data that I gather from the

> database
> > inside the html file using only asp.net, without any report generation

> tool
> > (click the button and there you go: window with the contract filled)? A
> > little more elaborated example would be highly appreciated as this is my
> > first ASP.NET app.

>
>
>

 
Reply With Quote
 
Karl Seguin
Guest
Posts: n/a
 
      10-05-2004
If you are stuck with templates in HTML, then you're only/best bet is to
read the HTML file into a string, like:

StringBuilder sb = null;
StreamReader sr = null;
try {
//CONSIDER CACHING THIS!!!
sr = new StreamReader(Server.MapPath("mytemplate.html"));
sb = new StringBuilder(sr.ReadToEnd());
}finally {
if (sr != null){
sr.Close();
}
}

foreach (DataColumn column in dt.Columns) {
sb.Replace(column.ColumnName, Convert.ToString(dt.Rows[0][column]));
}



then you can do someLIteral.Text = sb.ToString();

so your generate contract page will actually be an aspx file with a literal
on it. The code behind will read the HTML file and do as your boss suggests
(search/replace).

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


"Vlady" <> wrote in message
news:332B2C7A-C18E-4108-A421-...
> In my contract details page I have a GENERATE CONTRACT button. What does

it
> do? It retrieves the coresponding row from contracts table by ID, and the
> products child rows (nevermind this last one). After that I presume a
> Server.Transfer("blablablafile.htm") to the completed page with the

missing
> fields that I got from the table. But the problem is that in that html

(not
> aspx) there has to be no scripting code as I got it from my boss. It could
> have been easily resolved by use of Session in an aspx page but again "the
> boss" said that in html should be inserts like {variable_name}. Let me

know
> if it is necessary to further explain myself, as I am a little annoyed by
> this little thingie.
>
> "Karl Seguin" wrote:
>
> > To make sure i understand the question, let me rephrase it. You are
> > wondering how to put values from some data structure (say a dataset)

into a
> > web page. I take it the point to your question is that you don't want

to
> > manually have to do:
> >
> > txtEmail.Text = datatable.rows[0]["Email"];
> >
> > for some 100 fields?
> >
> > In asp.net 2.0 there'll be a DetailsView to help automate this otherwise
> > highly manual process
> >

(http://msdn.microsoft.com/asp.net/wh...library/en-us/
> > dnvs05/html/grddetview.asp#grddetview_topic5)
> >
> > Currently, you can look for a similar controls for 1.0...Your only other
> > alternative is to do something like:
> >
> > <table>
> > <tr>
> > <td>First Name</td>
> > <td><asp:textbox runat="server" id="firstName" /></td>
> > </tr>
> > <tr>
> > <td>LastName</td>
> > <td><asp:textbox runat="server" id="lastName" /></td>
> > </tr>
> > </table>
> >
> > then in codebehind:
> >
> > foeach (DataColumn column in datatable.Columns){
> > Control c = page.FindControl(c.ColumnName)
> > if (c != null){
> > if (typeof(c) == TextBox){
> > ((TextBox)c).Text = datatable.rows[0][column];
> > }else if (typeof(c) == RadioButtonList){
> > ....
> > }
> > }
> > }
> >
> > anyways, just some rough ideas...
> >
> > Karl
> > --
> > MY ASP.Net tutorials
> > http://www.openmymind.net/
> >
> >
> > "Vlady" <> wrote in message
> > news:94946B6C-3826-432D-BE45-...
> > > Hello. I recently built an ASP.NET "financial" application. I got to

the
> > > point where I have a HTML template (a contract) which needs to be

filled
> > with
> > > various data from the database. I put a "generate contract" button on

my
> > ASPX
> > > page, but I totally lack ideas of how to put the data in the correct

> > places
> > > in the html file. I was recommended (actually "do like this" from my

boss)
> > to
> > > enclose the variable name like this {variable_name} in the html, and

he
> > said
> > > that there are some functions to assign the value to the variable but

> > how???
> > > So the question is: how can I place the data that I gather from the

> > database
> > > inside the html file using only asp.net, without any report generation

> > tool
> > > (click the button and there you go: window with the contract filled)?

A
> > > little more elaborated example would be highly appreciated as this is

my
> > > first ASP.NET app.

> >
> >
> >



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enable a button when all three text boxes are filled data ahmed k ASP .Net Web Controls 0 09-25-2010 03:39 AM
Word template to be filled by the server in aspnet sweetpotatop@yahoo.com ASP .Net 9 02-15-2006 02:30 PM
Easy Question. Create a datagrid filled with data without any code on web page? Roger ASP .Net 2 05-20-2005 06:23 PM
Drawing a <SELECT> list filled with Access data CLIENTside ? Phil Di Guillielmo HTML 4 02-05-2004 11:23 AM
Re: A Newbie Question about template template template Chris Theis C++ 2 07-24-2003 09:42 AM



Advertisments