Thursday, April 28, 2005

DataSource WebControls in ASP.NET 2.0

ASP.NET 2.0 comes with lots of new ready to use widgets. It can reduces lots of repeatative coding work many have been doing through out for years. One Prominent set of controls(without any UI) are the DataSource WebControls which can be bound to any control as a data provider.

See an example where the SqlDataSource is bound to a New GridView control:

<!DOCTYPE HTML PUBLIC 
"-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<BODY>
<FORM runat="server">
<asp:SqlDataSource
id="SqlDataSource1"
runat="server"
DataSourceMode="DataReader"
ConnectionString="Data Source=localhost;
Integrated Security=SSPI;
Initial Catalog=Northwind;"
SelectCommand="SELECT FirstName,
LastName, Title
FROM Employees">
</asp:SqlDataSource>
<asp:GridView id="GridView1"
runat="server"
DataSourceID="SqlDataSource1">
</asp:GridView>
</FORM>
</BODY>
</HTML>

No comments: