Asp. Guide to using Web DataGrid in net

Source: Internet
Author: User
Long ago wanted to write something about datagrid/datalist, but has always been, on the one hand, the study is not deep, on the other hand, the total feel no writing, a drag and drop, from the beginning of the idea has been more than a year.
Datagrid/datalist in the asp.net of importance, I must not stress again, where the table type of data display, most of the use of these two controls (of course, if who still write like the ASP asp.net, then I have no way), so, Everyone may have their own understanding, this article, is a kind of a tip for everyone to do a foreshadowing.
First, the method
1, DataBind
Very simple, most commonly used method. Binding data. There is only one point to note: After this method has been executed, the DataGrid (because the DataGrid and DataList are very similar, so the following introduction is for the DataGrid, but not far from the DataList) all the controls that display bound data. will display the data in the DataSource, and the remaining controls will be initialized to the state of the design in. aspx.
Second, the property
1, DataSource
Where there is databind, there should be datasource. If the datasource is not specified and the DataBind is executed, the DataGrid will not display anything.
DataSource is usually a dataset, a DataTable, or a DataView. You can, of course, bind DataReader or other classes that implement IEnumerable.
2, Datakeyfield,datakeys
After you have positioned a row in the DataGrid, you definitely want to know where this line is in the datasheet, at least five ways to do this, and setting the DataKeyField of the DataGrid is one of these methods.
DataKeyField is generally set to the unique field of the datasheet (otherwise meaningless), and you can get the value of the key field in the row by DataKey.
DataKeys is a collection of datakey that reads the datakey of the corresponding rows through the index of the rows.
3, Edititemindex,selectedindex,currentpageindex,selecteditem
These attributes are well understood, the name to know what the meaning, it should be noted that the EditItemIndex or currentpageindex after the need to perform the DataBind method (of course, the previous mentioned, also need to set DataSource).
4, Columns
There's nothing to explain, columns is columns, a collection of columns, you can set properties for columns, including visible, HeaderText, Footertext, SortExpression, and so on.

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.