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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

22 Experts available now in Live!

Get 1:1 Help Now