To get the data contents of the columns in a data item in the DataGrid control

Source: Internet
Author: User
Datagrid|datagrid Control | data

In the DataGrid control, the data is typically displayed in a bound column or template column.

You typically want to get data for a column of a data item when you are writing a method of handling the event for the DataGrid control (the control named DG1).

In addition to the Selectedinexchanged event, the parameter E of the processing method for the other events is an instance of the DataGridCommandEventArgs class. With the E instance, you can get the data in the data item that raised the event.

1. Get the data in the bound column

1 is not in edit state, or the data item is in edit state but the bound column is read-only

e.item.cells[column index]. Text

2) in Edit state

Bound columns appear as TextBox controls if they are in edit mode

((TextBox) (e.item.cells[column index). Controls[0]). Text

2. Get the data in the stencil column

You can place one or more controls in a template column (right-click the Edit Template menu), these controls can bind to data in a data source to obtain data that is bound to a control on a template column, first know the ID of the control, and then obtain a reference to the control by using the FindControl method.

(control type) (e.item.cells[column index). FindControl ("Control ID")). Properties of the control
Eg: (CheckBox) (E.item.cells[3]. FindControl ("Cbsex")). Checked



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.