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

Discussion in 'ASP .Net' started by =?Utf-8?B?VmxhZHk=?=, Oct 4, 2004.

  1. 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.
     
    =?Utf-8?B?VmxhZHk=?=, Oct 4, 2004
    #1
    1. Advertising

  2. 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.
     
    =?Utf-8?B?S2VuIENveCBbTWljcm9zb2Z0IE1WUF0=?=, Oct 4, 2004
    #2
    1. Advertising

  3. =?Utf-8?B?VmxhZHk=?=

    Karl Seguin Guest

    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/whidbey/default.aspx?pull=/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:...
    > 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.
     
    Karl Seguin, Oct 4, 2004
    #3
  4. Re: Howto:HTML template which needs to be filled with data from a

    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/whidbey/default.aspx?pull=/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:...
    > > 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.

    >
    >
    >
     
    =?Utf-8?B?VmxhZHk=?=, Oct 5, 2004
    #4
  5. =?Utf-8?B?VmxhZHk=?=

    Karl Seguin Guest

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

    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:...
    > 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/whidbey/default.aspx?pull=/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:...
    > > > 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.

    > >
    > >
    > >
     
    Karl Seguin, Oct 5, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roger
    Replies:
    2
    Views:
    403
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
    May 20, 2005
  2. Replies:
    9
    Views:
    7,927
  3. Phil Di Guillielmo
    Replies:
    4
    Views:
    1,920
    Bob Barrows
    Feb 5, 2004
  4. Aykut Canturk
    Replies:
    2
    Views:
    498
    Munna
    Jun 4, 2008
  5. ahmed k
    Replies:
    0
    Views:
    1,301
    ahmed k
    Sep 25, 2010
Loading...

Share This Page