I am trying to work thru some sample code.
The code I am having a problem with is:
private ListControl GetSelectedList()
{
return (ListControl)FindControl(ddlControls.SelectedItem.Value);
}
ddlControls is a DropDownListBoxControl collection
What does the ddlControls.SelectedItem.Value return (its a numeric value, but I don’t know what it represents)?
2nd question: What is return (ListControl)FindControl(ddlControls.SelectedItem.Value); ?
Thanks
SelectedItem.Value, as the name suggests, is the value of the currently selected item in the drop-down list. For example, if this were a list of months and someone had selected “September”, this property has the value “September”.FindControlis a method that looks up controls by their id. Using our example from before, it would try to find a control with the name “September”. The(ListControl)at the beginning is a cast; theGetSelectedList()method is implicitly assuming that every possible answer you could get fromddlControlsis the name of anotherListControl. (This might not be a good idea depending on the circumstances.)The result — that is, the control whose id is the same as the currently selected value in
ddlControls— is then returned, and that’s the result ofGetSelectedList().