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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
edit .asp files 5 31
bound data table problem 2 33
JSON Deserialize issue 6 26
How can I do Unit Testing with Session ? 1 11
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

838 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