Home > Microsoft .Net Development Tips > ASP.NET Development > Calling a detail data form from a DataGrid row
Win Development Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ASP.NET DEVELOPMENT

Calling a detail data form from a DataGrid row


Roger McCook
12.11.2002
Rating: -4.67- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


This tip was submitted to the Visual Studio .NET Info Center tip exchange by member Roger McCook. Let other users know how useful this tip is by rating it below. Got a tip or code of your own you'd like to share? Submit it here!

Introduction
The idea is that we have a DataGrid that has a list of records in a database table. We want to be able to select a row and call up a detail form that will have the corresponding database detail.

Using Visual Studio .NET, I drag and drop a DataGrid onto my Web form and start tinkering with the properties. This is the way I like to do it but I still have to switch to HTML view and code a few items by hand. Here is some actual code from a recent project I worked on for a large company in Atlanta. The grid is generalized to handle several different reference tables in the database. The detail form that will be called is dependent on which table I'm working with.

Most of the code was generated automatically by Visual Studio (VS.NET Enterprise Edition), but I had to switch to HTML view and add a couple of lines myself. The following info was manually entered: This following line (from above) calls a procedure named "myDataGrid_PageChanger" when I want to move forward or backward a page.

OnPageIndexChanged="myDataGrid_PageChanger"

These following lines (from above) put an EDIT button and a DELETE button in each row.

This following line (from above) calls a procedure named "myDataGrid_ItemCommand" when one of the above buttons is clicked.

OnItemCommand="myDataGrid_


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
ASP.NET Development
How to use jQuery to solve Javascript browser compatibility problems
How to write an out-of-browser Silverlight 3 application in 3 steps
Silverlight 3 beta SDK download lets developers try new RIA features
Visual Studio's IntelliSense for jQuery doesn't autocomplete correctly
Dundas Map for .NET kicks up geographic visualization
Return to CodePlex: Into the Sandcastle…
VBScript Tutorial
Use PHP with Visual Studio to create Web sites
Visual Studio Team System Add-ins: Conchango Scrum for Team System and Scrum Dashboard
Visual Studio 2008 and .NET Framework 3.5 SP1 introduces ADO .NET Entity Designer

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


ItemCommand"


The following code is entered in the code-behind page in the page_load procedure. This is where I determine which table I'm working with and refresh the DataGrid accordingly.


The following procedure is entered in the code-behind file to refresh the DataGrid. Note how the SQL syntax changes depending on which table I'm working with.


The following procedure is called when you move forward or backward a page.


The following procedure is called when you click one of the command buttons in the DataGrid. Notice how I determine which button was clicked and how I pick out the Row_ID that I want to edit or delete.


Finally, there is one more procedure I'll show which is the EditRecord procedure. I'm not showing the DeleteRecord procedure because it is not relevant to this article. This is the code that redirects you to the appropriate detail form. By passing the database row in the call, you can write code in the detail form to fill the form from the database.

Conclusion
I've demonstrated how we can have a form with a DataGrid control that can be used generically for several database tables. The control will contain an EDIT button in each row. When you click the EDIT button, the program selects the appropriate detail form and opens it (passing in the row_id so that the detail form can be populated from the database.)

If you have any comments, corrections or other ideas, you can e-mail me at RogerMcCook@hotmail.com.

Roger D. McCook
McCook Software, Inc.

Rate this Tip
To rate tips, you must be a member of SearchWinDevelopment.com.
Register now to start rating these tips. Log in if you are already a member.




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Database Programming Solutions - .NET XML, Visual Studio LINQ, ORM .NET
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts