Testing the CodeGridWebControl


Visual Studio .NET offers some nice features for testing and debugging Web controls. All we have to do is add a Web Application project to the same solution and then reference the CodeControls project.

To test the sample application:

  1. Before creating the test application, make sure that you build the CodeControl project first.

  2. While keeping the grid control project open , choose File > New Project from the menu bar. Select ASP.NET Web application from the New Project dialog.

  3. Enter testproject for the name of the application, but before you click the OK button, click on the Add to Solution option. This will make the new project and the old be in the same solution (same session of VS.NET) ( Figure 9.67 ).

    Figure 9.67. Before clicking that OK button, make sure you select the Add to Solution option. This will make it easier to debug the control at the same time as you test it.

    graphics/09fig67.gif

  4. In the solution explorer, you'll see both projects. Right-click on the testproject and choose Set as Startup Project from the popup menu ( Figure 9.68 ).

    Figure 9.68. The CodeControls project is set to be the startup project by default, but we need the Test project to be the startup project. Web control projects are not executable programsthey're DLLs.

    graphics/09fig68.gif

  5. Right-click on the testproject again, and this time select Add Reference from the pop-up menu. Then, in the Add Reference dialog, click on the Projects tab. You'll see the CodeControls project. Double-click on the CodeControls entry to add it as a reference ( Figure 9.69 ).

    Figure 9.69. When you add a reference to the project, you also add a build dependency on that project. That means that VS.NET builds the referenced project first before building the test project.

    graphics/09fig69.gif

  6. Click OK to close the dialog. If you look at the Toolbox you should now see the CodeGridWeb control there ( Figure 9.70 ).

    Figure 9.70. As soon as you reference the CodeControl project, the control appears in the toolbox.

    graphics/09fig70.gif

  7. Add the control to the form as you would any other control; it should look like the one in Figure 9.71 .

    Figure 9.71. The CodeGridWeb control in all its glory . It's not as beautiful as the grid control that comes with Visual Studio .NET, but nothing beats making your own.

    graphics/09fig71.gif

graphics/tick.gif Tips

  • Whenever you build the test project VS.NET will build both projects at once.

  • Try changing some of the properties of the grid, like Rows and Columns. You'll see that the grid repaints itself as you change the settings. You can also try writing some code to set the contents of a cell in Page_Load , for example.




C#
C# & VB.NET Conversion Pocket Reference
ISBN: 0596003196
EAN: 2147483647
Year: 2003
Pages: 198
Authors: Jose Mojica

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net