ASP.NET & Databases Part 7
page 2 of 4
by . .
Feedback
Average Rating: 
Views (Total / Last 10 Days): 23150/ 70

Setting up the DataGrid

Setting up the DataGrid

First, there are several things that must happen to a DataGrid before you can sort -

  1. You must turn AutoGenerateColumns on (=true). This means that you will lose any special columns and lose the ability to edit the data. It is a wise idea to create one page for viewing and another for editing.

  2. You must add the attribute AllowSorting and set it to true. This makes each column header a link that will reload the page when clicked.

  3. You must add the attribute OnSortCommand and set it to the method that will sort the data (in this case dg_sort).

  4. You must add the method dg_sort.

We will be using the same page that we have been using for the whole series to view the data. See part 6 for a complete listing of that page. After making these changes, your DataGrid will look like this -

<asp:DataGrid id="dg" runat="server"
Bordercolor="black"
gridlines="vertical"
font-names="Arial"
font-size="10pt"
HeaderStyle-BackColor="#FFCC00"
ItemStyle-BackColor="#FFCC66"
AlternatingItemStyle-BackColor="#FFFFFF"
AutoGenerateColumns="True"
OnEditCommand="dg_edit"
OnCancelCommand="dg_cancel"
OnUpdateCommand="dg_update"
OnSortCommand="dg_sort"
AllowSorting="True"

>
</asp:dataGrid>

(The changes are in red.)

Here is a picture of what the DataGrid should look like -


View Entire Article

User Comments

Title: Nice Article   
Name: Viv
Date: 2004-11-01 2:02:39 AM
Comment:
Good Article.
Keep it up.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2019 ASPAlliance.com  |  Page Processed at 2019-11-20 7:11:36 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search