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
368 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…

730 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