Exforsys.com
 
Home Tutorials ASP.NET 2.0
 

ASP.NET : Using a Grid to Display Detail Information

 

ASP.NET 2.0 Free Tutorials : Using a Grid to Display Detail Information

In this tutorial you will learn how to use a GridView Control to display the details of the item selected in the DropDown list and test the page.



We shall now use a GridView to display the details of the item selected in the DropDown list.


1. Switch to or open the Default.aspx page (or the page you have been working with), and switch to Design view.


2. From the Data group of the Toolbox, drag a GridView control onto the page.


3. In the smart tag panel, from the Connect to Data Source list, select < New Data Source >.


4. In the smart tag panel, select Choose Data Source.


5. The Choose Data Source wizard starts.


6. From the Select a data source list, select < New Data Source >.


7. You will create a second data source that will get different data than the first data source control does.


8. The Data Source Configuration dialog box is displayed:


9. Select Database.


10. In the Specify an ID for the data source box, a default data source control name is displayed (SqlDataSource2). You can leave this name.


11. Click OK.


12. The wizard displays a page where you can select a connection.


13. From the Choose a data connection list, select the connection created and stored earlier.


14. Click Next.


15. The wizard displays a page where you can create a SQL statement.


16. From the Name list under Table or View Options, select StudentMaster.


17. In the Columns box, check StudentId, StudentName, and CourseId.


18. Click WHERE.


19. The Add WHERE Clause dialog box is displayed:


20. From the Column list, select CourseId.


21. From the Operator list, select =.


22. From the Source list, select Control.


23. Under Parameter Properties, in the Control ID list, select DropDownList1.



24. The last two steps specify that the query will get the search value for the category ID from the DropDownList control you added earlier.


25. Click Add.


26. Click OK to close the Add WHERE Clause dialog box.


27. Click Next.


28. In the Preview page, click Test Query.


29. The wizard displays a dialog box that prompts you for a value to use in the WHERE clause.


30. Type 22 in the box and click OK.





31. The records for CourseId 22 are displayed.


32. Click Finish to close the wizard.


33. The master-detail display can now be tested.


To test the page

1. Press CTRL+F5 to run the page.


2. When the page appears, Courses from the first item in the drop-down list are displayed.


3. Select a CourseId from the list and confirm that the corresponding Student records appear in the grid.




Read Next: ASP.NET Displaying Master-Detail Data on the Same Page



 

 

Comments


Dave said:

  Very straight forward, helped me a lot :D
January 2, 2007, 12:29 pm

darell said:

  what if you have "All" item from the collection of the dropdownlist. how can you show all items from the database if you have already set the SQL "where" statement?
March 7, 2007, 3:28 am

Fayaz Vaar said:

  It is of no use when u use Wizrds. Don't use wizards do what ever u can do writting code. Using Wizards is a silly job
April 23, 2007, 11:19 pm

Tanner said:

  So instead of displaying the student records in a grid..how could I make it render a user control instead? So if you picked an option from the list it would draw the control and allow use of it. I hope that makes sense.
May 22, 2007, 8:29 am

Mohsen1 said:

  this tutorial is best idea to learn asp and how to use information on db
July 21, 2007, 5:14 pm

Ekin said:

  Hello,

How can you use this same idea but have 2 drop down list??? In my case I have:

DropDownList1:
USA
Non-USA

DropDownList2:
Name
Type

Text Box to type in what user want to search and Search button to search base on what they've selected in both DropDownList. Each drop down value that the user selected is my AND in my query.

Example:

Select *
From home
Where flag = 1
AND DropDownList1.Selected Value = 'text in textbox'
AND DropDownList2.Selected Value = 'text in textbox'
July 2, 2008, 6:29 pm

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2010 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape