Web DataGrid User Guide in ASP. NET

Source: Internet
Author: User

A long time ago, I wanted to write something about DataGrid/DataList. However, on the one hand, I have not learned much about myself, and on the other hand, I have never been able to get started, it has been more than a year since the beginning.
DataGrid/DataList in ASP. NET, I do not need to emphasize any more. Most of the two controls will be used for displaying Table data (of course, if anyone writes ASP as ASP. NET, so everyone may have their own insights. This article is a good example to help you lay the groundwork.
I. Methods
1. DataBind
This is a simple and most commonly used method. Bind data. Note only one thing: After this method is executed, the DataGrid (because the DataGrid and DataList are very similar, the following introduction is not far from DataList although it is for the DataGrid) all the controls that display the bound data will display the data in DataSource, and other controls will also be initialized. the design status in aspx.
Ii. Attributes
1. DataSource
Where DataBind exists, DataSource exists. If DataBind is executed without a DataSource specified, the DataGrid will display nothing.
DataSource is generally DataSet, able, or DataView. Of course, you can also bind DataReader or other classes that implement IEnumerable.
2. DataKeyField, DataKeys
After you locate a row in the DataGrid, you must know the position of the row in the data table. There are at least five ways to do this. Setting DataKeyField in the DataGrid is one of these methods.
DataKeyField is generally set to the Unique field of the data table (otherwise it doesn't make sense). DataKey can be used to obtain the value of the corresponding keyword segment for this row.
DataKeys is a set of DataKeys that read the DataKey of the corresponding row through the row index.
3. EditItemIndex, SelectedIndex, CurrentPageIndex, SelectedItem
These attributes are well understood. You can see what the name means. Note that you need to re-execute the DataBind method after setting EditItemIndex or CurrentPageIndex (of course, as mentioned above, you also need to set DataSource ).
4. Columns
There is nothing to explain. Columns is Columns, a set of Columns. You can set column attributes, including Visible, HeaderText, FooterText, and SortExpression.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.