Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dropdownlist seleccteditem problem

Status
Not open for further replies.

briancostea

Programmer
Apr 21, 2005
82
US
when i submit the page, my dropdownlist.selecteditem is always the first one, regardless of what i change it to.

sub page_load
dim index as integer
select IIF(ObjDataReader("hotelbed") is dbNull.Value, "", ObjDataReader("hotelbed"))
case "single"
index = 0
case "double"
index = 1
case "queen"
index = 2
case "king"
index = 3
case "club level"
index = 4
case else
index = 0
end select
if drpHotelBed.Items.Count = 0 then
lItem = New ListItem("single", "single")
drpHotelBed.Items.Add(lItem)
lItem = New ListItem("double", "double")
drpHotelBed.Items.Add(lItem)
lItem = New ListItem("queen", "queen")
drpHotelBed.Items.Add(lItem)
lItem = New ListItem("king", "king")
drpHotelBed.Items.Add(lItem)
lItem = New ListItem("club level", "club level")
drpHotelBed.Items.Add(lItem)
end if
drpHotelBed.SelectedIndex = index
end sub

sub btnUpdate(sender as Object, e as EventArgs)
lblErr.text = drpHotelBed.SelectedItem.text
end sub

in the body:
<asp:DropDownList ID="drpHotelBed" runat="server"></asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="update" OnClick="btnUpdate"/>

i think it has something to do with where i set the index. is there something i can check in the page_load subroutine to tell if the page has been submitted? thanks - brian
 
in ASP.NET, page.ispostback will tell you if the load is the response to a REQUEST, e.g. TRUE if it's a postback, FALSE if not.

"I swear by my life and my love of it that I will never live for the sake of another man, nor ask another man to live for mine."
— John Galt
Atlas Shrugged

If you want to get the best response to a question, please check out FAQ222-2244 first

 
Err, not Page.IsPostBack, just IsPostBack.

"I swear by my life and my love of it that I will never live for the sake of another man, nor ask another man to live for mine."
— John Galt
Atlas Shrugged

If you want to get the best response to a question, please check out FAQ222-2244 first

 
what - no star? :)

"I swear by my life and my love of it that I will never live for the sake of another man, nor ask another man to live for mine."
— John Galt
Atlas Shrugged

If you want to get the best response to a question, please check out FAQ222-2244 first

 
Err, not Page.IsPostBack, just IsPostBack.
It is Page.IsPostBack really, it's just that as the page Inherits System.Web.UI.Page you don't have to type the "Page". section.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
YOU'RE%20A%20STAR!.JPG
 
What does that mean?!


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top