COMP 1020 Lecture Notes - Meridian Regional Airport, Data Binding, Xml

76 views3 pages
problem. SelectedIndex returns a zero-based index number that represents where the row occurs
in
the grid. This isn’t the information you need to insert into the query that gets the related records.
Instead, you need a unique key field from the corresponding row. For example, if you have a
table of
products, you need to be able to get the ProductID for the selected row. In order to get this
information,
you need to tell the GridView to keep track of the key field values.
The way you do this is by setting the DataKeyNames property for the GridView. This property
requires a comma-separated list of one or more key fields. Each name you supply must match
one of
the fields in the bound data source. Usually, you’ll have only one key field. Here’s an example
that tells
the GridView to keep track of the CategoryID values in a list of product categories:
<asp:GridView ID="gridCategories" runat="server"
DataKeyNames="CategoryID" ... >
Once you’ve established this link, the GridView is nice enough to keep track of the key fields
for the selected record. It allows you to retrieve this information at any time through the
SelectedDataKey property.
Often, a database search will return too many rows to be realistically displayed in a single page.
If the
client is using a slow connection, an extremely large GridView can take a frustrating amount of
time
to arrive. Once the data is retrieved, the user may find out it doesn’t contain the right content
anyway
or that the search was too broad and they can’t easily wade through all the results to find the
important information.
The GridView handles this scenario with an automatic paging feature. When you use automatic
paging, the full results are retrieved from the data source and placed into a DataSet. Once the
DataSet
is bound to the GridView, however, the data is subdivided into smaller groupings (for example,
with 20
rows each), and only a single batch is sent to the user. The other groups are abandoned when the
page
finishes processing. When the user moves to the next page, the same process is repeatedin
other
words, the full query is performed once again. The GridView extracts just one group of rows,
and the
page is rendered.
To allow the user to skip from one page to another, the GridView displays a group of pager
controls at the bottom of the grid. These pager controls could be previous/next links (often
displayed as
< and >) or number links (1, 2, 3, 4, 5, . . . ) that lead to specific pages. If you’ve ever used a
search
engine, you’ve seen paging at work.
Unlock document

This preview shows page 1 of the document.
Unlock all 3 pages and 3 million more documents.

Already have an account? Log in

Document Summary

Selectedindex returns a zero-based index number that represents where the row occurs in the grid. This isn"t the information you need to insert into the query that gets the related records. Instead, you need a unique key field from the corresponding row. For example, if you have a table of products, you need to be able to get the productid for the selected row. In order to get this information, you need to tell the gridview to keep track of the key field values. The way you do this is by setting the datakeynames property for the gridview. This property requires a comma-separated list of one or more key fields. Each name you supply must match one of the fields in the bound data source. Here"s an example that tells the gridview to keep track of the categoryid values in a list of product categories:

Get access

Grade+
$10 USD/m
Billed $120 USD annually
Homework Help
Class Notes
Textbook Notes
40 Verified Answers
Study Guides
Booster Classes
Class+
$8 USD/m
Billed $96 USD annually
Homework Help
Class Notes
Textbook Notes
30 Verified Answers
Study Guides
Booster Classes