It once again
and looked to see what's actually rendered in this page the page needs to
include a select control with a lot of options and so we need our drop-down
list to have these options with the text is the long name and the value is the
short name will see about to happen here's our control look at the markup is
nothing more than well a control with ASP drop-down list on the ASC X page okay.
Was look at
the code for this thing it's all done in the code in the markup that's all
there was a drop-down list and the story here in the class we have an array of
well at to Colin array of values short name, long name there a lot of other
data structures like reviews don't yell at me it was the simplest using an
array and that's why went with I like the array because it's easy to initialize
at design time so here is the contents of the array and in the page load event
handler we fill the list the load list procedure we go there simply clears out
the state drop-down list and loops through every item in the states array and
for each one adds a new item to the drop-down list by creating a new list item
and retrieving the short name.
Actually is the
long name and the short name because of the list item when you create one you
generate the text to be displayed first and the value second this is the text
to be displayed this is the value other also control properties I did auto post
back text and value was look at those here I have auto post back text and value
what is auto post back work with it gets the auto post back property of the
drop-down list and it sets the auto post back property of the drop-down list
can be easier met the value property gets the value of the selected item of the
drop-down list and sets the selected index to be the index corresponding to the
value supply remember if I type TX and push it into the value of this drop-down
list I need to figure out which index that is defined index procedure was a somewhat
brute force the five index procedure just scans the list to find a match once.
It finds a
match he returns the index believe me there are better ways to do this I didn't
want to dig into here esoteric means of searching data structures like It as
simple as possible so back up here I'll find it there we go the value when you
want to set we find the index and stick that in the selected index property of
the drop-down list finally there's a read only text property that retrieves the
text of the list and that returns the text of the selected item in the
drop-down list to the properties really aren't very complicated handling the
event requires a little.
0 comments:
Post a Comment