some dropdown webcontrol questions...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

whats the main difference between
cbo.SelectedItem.Value and cbo.SelectedValue. both return the same result, but why and when to use it? thanks
 
hi Asha,

both are same..its only the way you want to access it.
if run reflector and see whats this cbo.SelectedValue is

public virtual ListItem get_SelectedItem()
{ int num1;
num1 = this.SelectedIndex;
if (num1 >= 0)
{
return this.Items[num1];
}
return null;
}


so if you have reference to ListItem (that is cbo.SelectedItem) you can
access the value as listItem.value
or cbo.SelectedValue if you have reference to cbo.

hth,
Av.
 
add more to it, i would recommend cbo.SelectedValue to write less code and
make it faster.

Av.
 
cbo.SelectedItem.Value dates back to ASP.NET 1.0, and was left in the 1.1 framework for backwards compatability. The cbo.SelectedValue is new to 1.1, and is a lot nicer (in terms of writing code) if you are just doing 1.1 work.
 
Back
Top