A timesaver control: GridView
ASP.NET 2 has got several new foucs on development. Probably gridView will be your best friend of you. The GridView control automates many of the features of the DataGrid control. You have a full control on viewing, sorting, paging and editing. This sample is only a beginner guide but I hope that you will discover many features of gridView.
Let's see a short look at gridview control on a page.
First we have started our sample application dropping a SqlDataSource from toolbox. We need too create a custom database connection string and a sql command using sqldatasource wizard. Then drop GridView control into page. Choose data source and edit setting on gird. That's all. In next samples, we will look at how it is easy to edit and update any row in GridView. Our page source code is below. But you do not need to write any code, wizard builds everything automatically without tiring you!
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName], [City] FROM [Customers]">
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames="CustomerID"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True"
SortExpression="CustomerID" />
<asp:BoundField DataField="CompanyName" HeaderText="CompanyName"
SortExpression="CompanyName" />
<asp:BoundField DataField="ContactName" HeaderText="ContactName"
SortExpression="ContactName" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
</Columns>
</asp:GridView>
</div>
</form>
Happy Coding!



