Solved

ASPX newbie wants VS 12 to link one record in one table with multiple other records in another table.

Posted on 2013-01-10
3
357 Views
Last Modified: 2013-01-19
Using Visual Studi o 2012, I have a simple aspx web page where I can see an employee's basic info.  That is the top form on the web page.  I then have a bottom gridview that displays timeclock info for that employee.  I want to know if there is a way in Visual Studio 2012 to link these two so the gridview "gets" the employee records.  I tried to modify the SQL command but it is not working.  I don't seem to know how to change the gridview SQL to compare to the employee form 'employee number'.   I'm sure it's simple, but this is my first VS 12 app.  Please assist.  Thanks!
0
Comment
Question by:tperegoy
  • 2
3 Comments
 
LVL 12

Assisted Solution

by:Jared_S
Jared_S earned 250 total points
ID: 38762834
There are a couple of steps involved...

Bind the gridview during the databound event of the form (the value doesn't exist prior to that point).
Using a sqldatasource adapter, add a where statement to your sql query that
filters results in that query based on the value of the forms view.
Something like:
...
"where myTableValue = @variablename"

Then, using the sql data source adapter, select the value of the variable as being the selected value of your form view control.

If you have much other processing to do, assigning datakeynames in the formview and gridviews can be a time-saver for referencing the selected records.
0
 

Accepted Solution

by:
tperegoy earned 0 total points
ID: 38772078
OK, so far so good, but please remember, I'm new at ASP and VS 2012.  So I have the employee form open to edit and on the field EMPNO, I select databindings and  .... not sure what's next.  Current;y, it has Custom Binding: Bind("EMPNO").  On this employee form, I can roll down through the different employee records.  

From there, I want the timeclock gridview to show the records that are related to that employee.  In the gridview, I have select statement,
Select * from TIMECLOCK where ([Empno]=?).  The Parameter source is FORM.  The FormField is @EMPNO.  There is no default value.

It would seem that I need to identify the form number and the form name somewhere.  

Sorry so basic, but I'msure it will start coming together after I get over this hump.  Thanks!


WAIT...   NEVER MIND, I FOUND IT!

Maybe I had not explained well.  I did not want to program anything, I wanted to use the features of Visual Studio to accomplish this.  

This is how I did it:

I set up a form and three gridviews on one web site.  Each of the four (one form and three gridviews) used a difference SQLDataSource to view data.  Each of these data sources was looking at a different table in my database.  

To view one employee record in the form, and then the matching employee records in all three grid views, I clicked on each gridview SQLDataSource box (just below the gridview).   That opened the propoerties box in the right pane.  In that properties box, I selected SelectSQL.  The contents were "Query".  That's my query for my table data.  The only thing is that this was selecting all table data and not just the matching table data.  I then clicked on the |...| box on the right.  

Enter:
Parameter Source: Control.
ControlID: FormView1 (or whatever number yours is)

Now click on Show Advanced Properties.  Arrow down and find NAME.  In that field, enter the name of the matching field that is in FormView1.  For example, in my case, I am matching on EMPNO.  My form and all three gridviews have EMPNO.  So, I entered EMPNO here and I had already indicated FormView1 in ControlID.  Click OK to save and exit.   My SQL statement for this gridview will now read:

<asp:ControlParameter ControlID="FormView1" DefaultView="" Name="EMPNO" PropertyName="SelectedValue Type="Int32" />

Do this for the other gridviews.  Works perfect now!  As I scroll from employee to employee on the main form, the gridview data for each employee is displayed.
0
 

Author Closing Comment

by:tperegoy
ID: 38796045
I accepted my own comment because my original question was not answered.  I foudn the asnwer myself after the other comment got me started, but did not complete the answer.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

776 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