Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
382 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Assisted Solution

by:Jared_S
Jared_S earned 750 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

722 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