Solved

Creating input form and dataview in Visual Studio 2005 developer

Posted on 2008-10-13
25
454 Views
Last Modified: 2013-11-26
I created an Access program for timecard entry for our users but now have been asked to transition this into a web application using Visual Basic developer.  The data that is inputted will be populated to one table that will be exported to a .txt file and imported into our Accounting system.
I have attached a screen print of what my Access input page looks like to give you a visual of what I'm trying to accomplish.

The first thing on the entry page needs to be four unbound fields: W/E date, Week#, Empl ID & Employee Name(name should be pulled from an employee table where empl id = empl id keyed in.

The reason for the fields above is because the these fields must be listed in every record added and I want to avoid having the user to have to rekey the information for these fields for every record for the specific employee.

Second, there needs to be an input form for users to key in the information. Fields include employee id, w/e date, week# (all populated from the fields above), job#, cost code, hours, etc.

Third: Below the input form I need a view of the data to show what has been entered for that employee so far. For example, when the user keys in data for Empl# 1, when they hit the Submit button it automatically refreshes the view below to show the newly added record.  

I'm a newbie to VS and ASP.net and I'm not sure how to accomplish this.  I have created a web application and a Web form page but I'm not sure what controls to use for everything.  Also, what code do I use the empl id on the input form to filter the data displayed in my third section? I've looked all over the Internet and also have a book but I can't find anything that addresses my specific situation.

Any help would be greatly appreciated.






Timecardproject.jpg
0
Comment
Question by:imstac73
  • 13
  • 12
25 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22710802
Controls:  Label, Textbox, DropDownList, GridView, SqlDataSource, Button.
0
 

Author Comment

by:imstac73
ID: 22710917
Well I actually made some progress yesterday but I do have some specific questions.  You'll see on the image I sent that I have Employee ID and Employee Name in the top portion of the form.  Employee Name is automatically populated when Employee ID is keyed in.  What controls would I use for each field?  The Employee ID is a number field; not sure if that matters or not.  

In addition, the gridview at the bottom needs to be filtered by the Employee ID the user keys in at the top.  So I created a textbox for the Employee ID (not sure if this is right) and then added a Gridview and SQLDataSource.  In the data source I did a Select statement where the employee id from that data source equals the EmplID textbox control above. When I click to view in browser nothing comes up for the gridview.  Should I be using a different control for the employee id since it is a number?  Not sure why it won't show the gridview data.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22711126
For the EmployeeID, it looks like you just need a read-only TextBox.  If you don't see anything in the GridView, it is because you may not be selecting any data, or you haven't set the DataSourceID for the GridView to the ID for the SqlDataSource.
0
 

Author Comment

by:imstac73
ID: 22711290
I'm not sure what you mean by the read-only textbox.  The user must key in the Employee ID and then the Employee Name control should use the data that is entered int he Employee ID to pull the Employee Name.  I didn't know which data-bound control I needed to use for the Employee Name.  

On the gridview, here were my steps
Drag over gridview
Right-click gridview and select New for Choose Data Source
Select database and click OK
Select connection string
Select table and fields (Table: "Timecard", all fields)
Click Where button
Choose Employee ID column (column name; INEENO, type = decimal)
Use = Operator
Select 'Control' for Source
In Control ID select Empl ID textbox control (EmplID1)
Click Add and then OK
Test query (it returned the results when I keyed in the same employee id I am keying into the textbox.

Am I missing something? I've attached my code for this page.

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
 

<%@ Register Assembly="EclipseWebSolutions.DatePicker" Namespace="EclipseWebSolutions.DatePicker"

    TagPrefix="cc1" %>
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Untitled Page</title>

</head>

<body>

     <form id="DisplayResults" runat="server">

    <div>

        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;

        <table style="width: 712px">

            <tr>

                <td style="width: 389px; height: 22px">

                    W/E Date</td>

                <td style="width: 282px; height: 22px" align="left">

                    &nbsp;<cc1:DatePicker ID="DatePicker1" runat="server" Width="174px" />

                </td>

                <td style="width: 446px; height: 22px">

                    Week#</td>

                <td style="width: 446px; height: 22px">

                    <asp:DropDownList ID="DropDownList1" runat="server"><asp:ListItem>1</asp:ListItem>

                        <asp:ListItem>2</asp:ListItem>

                        <asp:ListItem>3</asp:ListItem>

                        <asp:ListItem>4</asp:ListItem>

                        <asp:ListItem>5</asp:ListItem>

                    </asp:DropDownList></td>

            </tr>

            <tr>

                <td style="width: 389px; height: 22px">

                    Employee ID</td>

                <td id="EmplID" style="width: 282px; height: 22px">

                    <asp:TextBox ID="EmplID1" runat="server" Width="106px"></asp:TextBox>

                    &nbsp;

                </td>

                <td style="width: 446px; height: 22px">

                    Employee Name</td>

                <td style="width: 446px; height: 22px">

                    &nbsp;&nbsp;&nbsp;&nbsp;

                </td>

            </tr>

        </table>

        <hr />

        &nbsp;&nbsp;

        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"

            AutoGenerateColumns="False" DataSourceID="SqlDataSource1">

            <Columns>

                <asp:BoundField DataField="INSTAT" HeaderText="INSTAT" SortExpression="INSTAT" />

                <asp:BoundField DataField="INCONO" HeaderText="INCONO" SortExpression="INCONO" />

                <asp:BoundField DataField="INDVNO" HeaderText="INDVNO" SortExpression="INDVNO" />

                <asp:BoundField DataField="INEENO" HeaderText="INEENO" SortExpression="INEENO" />

                <asp:BoundField DataField="INCKTY" HeaderText="INCKTY" SortExpression="INCKTY" />

                <asp:BoundField DataField="INERCD" HeaderText="INERCD" SortExpression="INERCD" />

                <asp:BoundField DataField="INWKNO" HeaderText="INWKNO" SortExpression="INWKNO" />

                <asp:BoundField DataField="INDYWK" HeaderText="INDYWK" SortExpression="INDYWK" />

                <asp:BoundField DataField="INGLAN" HeaderText="INGLAN" SortExpression="INGLAN" />

                <asp:BoundField DataField="INJBNO" HeaderText="INJBNO" SortExpression="INJBNO" />

                <asp:BoundField DataField="INJCDI" HeaderText="INJCDI" SortExpression="INJCDI" />

                <asp:BoundField DataField="INCSTY" HeaderText="INCSTY" SortExpression="INCSTY" />

                <asp:BoundField DataField="INRGHR" HeaderText="INRGHR" SortExpression="INRGHR" />

                <asp:BoundField DataField="INOVHR" HeaderText="INOVHR" SortExpression="INOVHR" />

                <asp:BoundField DataField="INOTHR" HeaderText="INOTHR" SortExpression="INOTHR" />

                <asp:BoundField DataField="INOTTY" HeaderText="INOTTY" SortExpression="INOTTY" />

                <asp:BoundField DataField="INDTWE" HeaderText="INDTWE" SortExpression="INDTWE" />

                <asp:BoundField DataField="INDPNO" HeaderText="INDPNO" SortExpression="INDPNO" />

                <asp:BoundField DataField="NOTES" HeaderText="NOTES" SortExpression="NOTES" />

                <asp:BoundField DataField="USERID" HeaderText="USERID" SortExpression="USERID" />

            </Columns>

        </asp:GridView>

        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CMSConnectionString %>"

            SelectCommand="SELECT * FROM [Timecard] WHERE ([INEENO] = @INEENO)">

            <SelectParameters>

                <asp:ControlParameter ControlID="EmplID1" Name="INEENO" PropertyName="Text" Type="Decimal" />

            </SelectParameters>

        </asp:SqlDataSource>

    </div>

         &nbsp; &nbsp; &nbsp; &nbsp;

        

    </form>

</body>

</html>

Open in new window

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22711988
1) I can only propose solutions from what you explain, so sometimes there are assumptions that can get us both into trouble.

2) You don't need a TextBox with ReadOnly = True, since you need to enter an EmployeeID.  That would just be a regular TextBox.

3) You can check what the SqlDataSource is pulling for you like this example:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim view As DataView = TryCast(Me.SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView)

        For Each drv As DataRowView In view
            Dim toAddress As String = drv("ToAddress").ToString()
        Next
    End Sub

0
 

Author Comment

by:imstac73
ID: 22712221
I thought using the Test Query function located in the SQLdatasource showed me what the data source was pulling; should this not be used?
What data bound control should I use to pull the Employee Name?
Did my code attached look okay?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22712288
1) The Test Query option in the designer should give you the same results, so when it doesn't you need to find a reason.

2) Troubleshooting with anything is about finding a way to testing things explicitly, and not just using assumptions about how it "should work".

3) Your code looked good on the surface, but it is difficult to see any reason why it won't work for you.

4) Did you try the test code that I showed you above?
0
 

Author Comment

by:imstac73
ID: 22712323
The Test Query gave me the results I was looking for.  Where exactly do I insert this code into my web form?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22712358
That code shows that you need to insert it into the Page_Load event handler.
0
 

Author Comment

by:imstac73
ID: 22712397
Where is that? I am new to VS; this is my first web applcation.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22712437
You can just copy that code from the comment, and paste it into the code-behind for the page.  If you don't have a code-behind, then you will need a <script> block.  With VWD, you would double-click on the web page in the designer to create the default Page_Load event handler.
0
 

Author Comment

by:imstac73
ID: 22712500
Is the code-behind page the one that ends with .vb?  I tried pasting it into this and it gave me an error "Statement is not valid in a namespace".  I tried double-clicking on the web page and nothing happened.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 22712578
The code-behind (i.e. Default.aspx.vb) should look like this:
Imports System.Data
 

Partial Class _Default

    Inherits System.Web.UI.Page
 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim view As DataView = TryCast(Me.SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView)
 

        For Each drv As DataRowView In view

            Dim toAddress As String = drv("ToAddress").ToString()

        Next

    End Sub
 

End Class

Open in new window

0
 

Author Comment

by:imstac73
ID: 22712661
It says the Dataview and RowView is not defined.  
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22712695
You missed the Imports System.Data at the top of the code module.
0
 

Author Comment

by:imstac73
ID: 22712773
I received the following attached error when I hit Ctrl-F5.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22712830
1) Nothing attached.

2) You should be using F5 to start with debugging.
0
 

Author Comment

by:imstac73
ID: 22713087
Here is the file again.
The debugger gave the error on this line of code.
        For Each drv As DataRowView In view

error.jpg
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22713157
It doesn't look like you are starting with debug, as I was trying to tell you before (F5 and not Ctrl-F5).  It sounds like the Me.SqlDataSource1.Select is returning a different type, and not DataView.  The TryCast tries to cast the object type to DataView, and if it fails, it returns Nothing, which would explain that exception.  You might be getting an IDataReader.
0
 

Author Comment

by:imstac73
ID: 22713280
No, I clicked F5 because it required me to enable debugging before it would work.  I am using a gridview control to display my data; not sure if that's what you mean.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22713967
Let's check this:

1) You run the web site application, and nothing displays on the screen.

2) You enter an Employee ID in the TextBox.

3) You click on the <Submit> button

4) Does anything display after clicking the button?
0
 

Author Comment

by:imstac73
ID: 22720807
I don't have a Submit button.  I assumed that when I keyed in the employee id the gridview would automatically display the records that have already been keyed in for that employee; is this not the case?

What code do I need to put in the Submit button for it to show the gridview?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22731447
There needs to be an action that causes the page to post back, like a Button, or setting the TextBox.AutoPostBack property.
0
 

Author Comment

by:imstac73
ID: 22736376
So I enabled Postback on my textbox and my gridview started working.  Whoohoo!

I had just couple other questions for you.
1. Is there a control that is equivalent to the Access combobox?  Want I want to do is allow users to have the choice of either keying in data or selecting it from the dropdown.  The combobox in VS doesn't allow you key in the data.

2. Is there a way to populate a textbox with data based on another field's data without databinding it? I don't want a data connection where the user can change my master table data. I just want to populate a control with the data and then allow them to change what is populated just on the form.  I will be creating a Submit button that will insert either what is populated or what they key into a different table.  

I hope this makes sense; it's kinda hard for me to explain.

Thanks.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 22757816
For ASP.NET, it would be the DropDownList control, which doesn't allow you to enter text.  

You would need to find an editable DropDownList control, like here:

Editable DropDownList in ASP.NET
http://weblogs.asp.net/coltk/archive/2003/09/17/27772.aspx
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

      Install BugTracker on Windows 2008 server Step 1:  Install windows 2008 server 32 bit OS and configure IIS. Step 2:  Install SQL server ( SQL server 2005 or SQL server 2005 Express edition. The installer for 2008  version isn’t very f…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now