Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prompt for table data & create a table?

Status
Not open for further replies.

markdmac

MIS
Dec 20, 2003
12,340
US
I am hoping someone can assist me as I really don't know where to start with this. I am looking to create what I hope is a simple ASP.Net page. I need to provide five boxes for input (name, email, address, certification date, referral date) and hopefully have a button to add this to a table that will appear below the input boxes. I need to also have a second button that will display the contents of the table with name & email on one line and then the remaining fields on a second line for each entry in the table. I need the ability to add a custom header & footer to this as well.

The resulting new page will then get printed to a PDF to be included in an email unless there is a way to put this same data directly into an email as a message body. The trick here is I am hoping to make this work for both PC and Mac clients.

I'm a PADI Assistant Instructor and am trying to automate a very manual process they put us through to record certifications so this isn't anything I'm doing for profit etc, I want to make this solution available for free to all my fellow dive pros. While I am a scripting samurai when it comes to VBScript, I really suck at VB.Net. I have my own Windows based server to load any code on.

Can anyone assist with some sample code that could get me started? Once I have the core function down I will use the header/footer info to duplicate the rest of the form that we have to fill out.



I hope that helps.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 

Does the data entered and displayed in the table on the screen need to be stored in a database of some sort, or would it be disposed of when the email was created? Do you have a database solution already in place and just need help with the interface?



Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
Mark, it will just be disposed of. I will eventually try to add functionality to store some bits of info in a cookie, but I can figure that bunch out later.

I hope that helps.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Don't want my previous reply to confuse you. I would later want to store the user's name and dive pro number in a cookie so they don't have to enter that each time. The info I am looking to add to the table would always be disposed of. The cookie would be great but I will deal with that later.
 

I'm not quite sure on what your final product will be, but thought I could at least give you something to start with. It's a very simple example to get input, store that info in a datatable and show in a gridview. Assuming you have a project started and created a page, you should be able to copy the following into it (providing it's in VB). It does no real validation other than a date check.

The .aspx markup (copy into the <body>)

Code:
<form id="frmMain" runat="server">
    <div>
        <table>
            <tr>
                <td>
                    Name
                </td>
                <td>
                    <asp:TextBox runat="server" ID="txtName" Width="200px"></asp:TextBox>
                </td>
                <td>
                    Address
                </td>
                <td>
                    <asp:TextBox runat="server" ID="txtAddress" Width="250px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Email
                </td>
                <td>
                    <asp:TextBox runat="server" ID="txtEmail" Width="200px"></asp:TextBox>
                </td>
                <td>
                    Certification Date
                </td>
                <td>
                    <asp:TextBox runat="server" ID="txtCertificationDate" Width="75px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Referral Date
                </td>
                <td>
                    <asp:TextBox runat="server" ID="txtReferral" Width="75px"></asp:TextBox>
                </td>
                <td colspan="2">
                    &nbsp
                </td>
            </tr>
            <tr>
                <td colspan="4" align="center">
                    <asp:Button runat="server" ID="btnSave" Text="Save" Width="150px" />
                </td>
            </tr>
        </table>
        <br />
        <br />
        <asp:GridView runat='server' ID="gvNames" DataKeyNames="id" CellPadding="4" ShowFooter="True"
            ShowHeader="true" AutoGenerateColumns="False" BackColor="White" BorderColor="#3366CC"
            BorderStyle="None" BorderWidth="1px">
            <Columns>
                <asp:BoundField DataField="ID" HeaderText="ID" />
                <asp:BoundField DataField="Name" HeaderText="Name" />
                <asp:BoundField DataField="email" HeaderText="Email" />
                <asp:BoundField DataField="Address" HeaderText="Address" />
                <asp:BoundField DataField="CertificationDate" HeaderText="CertificationDate" DataFormatString="{0: MM/dd/yyyy}" />
                <asp:BoundField DataField="ReferralDate" HeaderText="ReferralDate" DataFormatString="{0: MM/dd/yyyy}" />
            </Columns>
            <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
            <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
            <RowStyle BackColor="White" ForeColor="#003399" />
        </asp:GridView>
    </div>
    </form>

and this into the to code behind for that page:

Code:
Public Property AllMyNames() As DataTable
        Get
            Return ViewState("NamesDataTable")
        End Get
        Set(ByVal value As DataTable)
            ViewState("NamesDataTable") = value
        End Set
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            ' define the datatable
            Dim dtNames As New DataTable
            dtNames.Columns.Add("ID", GetType(Integer))
            dtNames.Columns.Add("Name", GetType(String))
            dtNames.Columns.Add("Email", GetType(String))
            dtNames.Columns.Add("Address", GetType(String))
            dtNames.Columns.Add("CertificationDate", GetType(Date))
            dtNames.Columns.Add("ReferralDate", GetType(Date))
            ' set in viewstate
            AllMyNames = dtNames
        End If
    End Sub

    Private Sub btnSave_Click(sender As Object, e As System.EventArgs) Handles btnSave.Click
        Dim dt As DataTable = AllMyNames
        Dim dr As DataRow = dt.Rows.Add
        dr("ID") = dt.Rows.Count
        dr("Name") = txtName.Text
        dr("Address") = txtAddress.Text
        dr("Email") = txtEmail.Text
        If IsDate(txtCertificationDate.Text) Then
            dr("CertificationDate") = CDate(txtCertificationDate.Text)
        End If
        If IsDate(txtReferral.Text) Then
            dr("ReferralDate") = CDate(txtReferral.Text)
        End If
        dt.AcceptChanges()
        AllMyNames = dt
        ' show the new name in the datagrid
        gvNames.DataSource = AllMyNames
        gvNames.DataBind()
    End Sub


Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top