advertisement
Login | Register   
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   TIP BANK
Browse DevX
Download the code for this article
It's easy enough to connect your DataGrid up to an ADO.NET provider, but not quite so easy to construct a custom provider. Did this article help? Do you want more information about this topic? Let us know in the csharp.general discussion group.
Partners & Affiliates
advertisement
advertisement
advertisement
advertisement
 

Write Your Own Provider For the ASP.NET DataGrid

The ASP.NET DataGrid is a very powerful control, capable of displaying anything that can be represented in tabular format. Find out how you can use it more effectively by creating custom data providers to populate your grids.  


advertisement
When was the last time you used the ASP.NET DataGrid control with something other than an ADO.NET provider? Chances are, like many developers, you haven't. The DataGrid control has such a well-publicized relationship with ADO.NET that it's difficult to imagine it doing anything useful on its own. Yet, by understanding and programming to the interfaces the DataGrid uses to obtain data, you can turn it into an extremely flexible tool that can display any type of information on a web page.

By now, every ASP.NET programmer is familiar with the following two lines of code:


myGrid.DataSource = mySqlDataReader;
myGrid.DataBind();

The first line tells the grid control to accept the DataReader mySqlDataReader as the data source, and the second line instructs it to go ahead and display whatever is in the reader in an HTML table. The key to getting the data grid to accept a custom provider is to know which interfaces of ADO.NET it uses to obtain the data, and then developing your code to implement those interfaces. Although there are a variety of such constructs you can choose from, the most suitable one for a read-only presentation is the IEnumerable interface, which you'll find in the System.Collections namespace.

It's quick, easy and you get access to all the articles on DevX.
This registration/login is to allow you to read articles on devx.com.
Already a member?



advertisement