asp.net.ph

DataList.SelectedItem Property

System.Web.UI.WebControls Namespace   DataList Class


Returns the selected item in a DataList control.

Syntax


Script [ DataListItem variable = ] DataList.SelectedItem

This property can only be used programmatically; it cannot be set when declaring the control.

Property Value


variable Returns a DataListItem that represents the item selected in the DataList.

The property is read only with no default value.

Remarks

Use the SelectedItem property to get a DataListItem object that represents the item selected in the DataList control. This object can then be used to access the methods and properties of the selected item.

Example

The following example demonstrates using the SelectedItem property to determine the selected item in a DataList control, display its contents and modify its properties.

void getSelected ( Object src, DataListCommandEventArgs e ) {
   myList.SelectedIndex = e.Item.ItemIndex;
   populateList ( );
   msg.Text = "The item selected is <b>" + 
    ( ( Label ) myList.SelectedItem.FindControl ( "title" ) ).Text + "</b>";
}

void chgBackColor ( Object src, EventArgs e ) { 
   if ( myList.SelectedItem != null ) {
      myList.SelectedItem.BackColor = System.Drawing.Color.Khaki;
   }
}
  C# VB

 Show me 

See Also

DataList Members   SelectedIndex   SelectedIndexChanged   SelectedItemTemplate   SelectedItemStyle   Allowing Users to Select Items in a DataList Control Skip Navigation Links




Previous page Back to top Next page

Check out related books at Amazon

© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note