Wednesday 13 March 2013

SelectedRow vs DataRow

This post describes the difference between SelectedRow and DataRow properties in a DataGrid.

Here are some examples used to demonstrate the difference between the 2 properties :

I have a DataGrid as displayed below:

Scenario 1: SelectedRow
  • This property is used to reference a selected DataGrid row.
  • SelectedRow value is passed through if a user clicks on the row, which means that the SelectedRow property will not work unless it is assigned within a click event (such as Button click or Link click)
  1. Select a row in DataGrid.
  2. Click ‘Display Selected Row’ button.
  3. You will notice that the label has been populated with the SelectedRow.EmployeeID value.
For this example, the SelectedRow value is assigned within the Button Click event :

Scenario 2: DataRow
  • This property is used to reference a Text column in the current row of a DataGrid control.
  • The DataRow property is available from within the DataGrid’s dropdown column.
  • Since the value can be populated without a user action, it does not need to be assigned AND is unavailable within a click event.
Example :
  1. Add a Dropdown column in the DataGrid called ‘DataRow Value’
  2. Set the DataSource value as displayed. (Notice that the parameter is assigned to DataRow.EmployeeID)
You will notice that when the page loads, the ‘DataRow Value’ column will be populated with the Employee ID value for the current row.

No comments:

Post a Comment