DropDownList SelectedValue? Or ClientID?

  • Thread starter Thread starter Richard Morse
  • Start date Start date
R

Richard Morse

Hi! I'm trying to use a DropDownList in an .aspx file that bases data
off of a database. I'm using the .NET Framework 1.1. According to the
documentation, I should be able to assign a value to the SelectedValue
property, and this would tell the DropDownList to use a particular value
as the initial display value.

This is being done in a Repeater.

However, it doesn't seem to work -- that is, nothing gets set to be the
initial value, so it always uses the first value in the menu.

In an attempt to fix this, I tried to insert javascript on the client,
using the "ClientID" property to properly select the item and set the
value this way (which is more of a problem). However, the ClientID
always is just the control name -- none of the rest of the ID that
serves to differentiate it from the other "site_id"s created by the
repeater.

Has anyone seen anything like this before? Any ideas of how I can get
the SelectedValue property working (which would be my preference)?

Thanks,
Ricky
 
You can change SelectedValue only after binding the DropDownList. Assign ur
value to the SelectedValue just after the call DataBind() on instance of
DropDownList in code behind.

Abhijeet Dev
 
Richard Morse said:
Hi! I'm trying to use a DropDownList in an .aspx file that bases data
off of a database. I'm using the .NET Framework 1.1. According to the
documentation, I should be able to assign a value to the SelectedValue
property, and this would tell the DropDownList to use a particular value
as the initial display value.

This is being done in a Repeater.

However, it doesn't seem to work -- that is, nothing gets set to be the
initial value, so it always uses the first value in the menu.

In an attempt to fix this, I tried to insert javascript on the client,
using the "ClientID" property to properly select the item and set the
value this way (which is more of a problem). However, the ClientID
always is just the control name -- none of the rest of the ID that
serves to differentiate it from the other "site_id"s created by the
repeater.

Has anyone seen anything like this before? Any ideas of how I can get
the SelectedValue property working (which would be my preference)?

Hi! The problem was that I was using the "onItemCreated" event of the
Repeater, when I should have been using the "onItemDataBound" event.

Sorry for the poor question,
Ricky
 
Back
Top