Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DropdownList: How to select by value programaticly?

Reply
Thread Tools

DropdownList: How to select by value programaticly?

 
 
Northern
Guest
Posts: n/a
 
      07-19-2003
I have an ASP DropdownList populated. What I want is to
select a new item, in my code, by set a datavale to
dropdownlist's selectedItem.Value property. I did the
following:

MyDropdown.SelectedItem.Value = "value 1"

Even though the "value 1" is in the dropdownlist's data
value collection, the dropdown's datatext doesn't change.

What am I doing wrong here? How should I do this?

Please help!

 
Reply With Quote
 
 
 
 
Rajeev Soni
Guest
Posts: n/a
 
      07-19-2003
You should say

MyDropdown.SelectedIndex = <Index of the Item you want to select.>

Rajeev

"Northern" <(E-Mail Removed)> wrote in message
news:05d001c34da9$49e10000$(E-Mail Removed)...
> I have an ASP DropdownList populated. What I want is to
> select a new item, in my code, by set a datavale to
> dropdownlist's selectedItem.Value property. I did the
> following:
>
> MyDropdown.SelectedItem.Value = "value 1"
>
> Even though the "value 1" is in the dropdownlist's data
> value collection, the dropdown's datatext doesn't change.
>
> What am I doing wrong here? How should I do this?
>
> Please help!
>



 
Reply With Quote
 
 
 
 
Northern
Guest
Posts: n/a
 
      07-19-2003
Thank you so much Ken. That's exactly what I need.
You are the MVP!

Thank a million!
>-----Original Message-----
>Hi,
>
>If I understand what you're after, you need to determine

the index of the value
>you are seeking and then set the SelectedIndex property

with that. The example
>below might be what you need. Let us know?
>
>Ken
>MVP [ASP.NET]
>
> Private Sub Button1_Click _
> (ByVal sender As System.Object, _
> ByVal e As System.EventArgs) _
> Handles Button1.Click
> DropDownList1.SelectedIndex = _
> DropDownList1.Items.IndexOf _
> (DropDownList1.Items.FindByValue("Green"))
> End Sub
>
>'---------------------------------------------------------

------
> <form id="Form1" method="post" runat="server">
> <p>
> <asp:dropdownlist id="DropDownList1"

runat="server">
> <asp:listitem value="Red">Red</asp:listitem>
> <asp:listitem value="Blue">Blue</asp:listitem>
> <asp:listitem value="Green">Green</asp:listitem>
> </asp:dropdownlist></p>
> <p>
> <asp:button id="Button1" runat="server"

text="Select
>Green"></asp:button></p>
> </form>
>
>
>"Northern" <(E-Mail Removed)> wrote in message
>news:05d001c34da9$49e10000$(E-Mail Removed)...
>I have an ASP DropdownList populated. What I want is to
>select a new item, in my code, by set a datavale to
>dropdownlist's selectedItem.Value property. I did the
>following:
>
>MyDropdown.SelectedItem.Value = "value 1"
>
>Even though the "value 1" is in the dropdownlist's data
>value collection, the dropdown's datatext doesn't change.
>
>What am I doing wrong here? How should I do this?
>
>Please help!
>
>
>.
>

 
Reply With Quote
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      07-19-2003
Glad to hear that it worked for you!

Ken

"Northern" <(E-Mail Removed)> wrote in message
news:008701c34e22$8c8050e0$(E-Mail Removed)...
Thank you so much Ken. That's exactly what I need.
You are the MVP!

Thank a million!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
select gridview row without using select button? =?Utf-8?B?RGFiYmxlcg==?= ASP .Net 5 02-27-2009 02:56 AM
Find value of SELECT if VALUE attribute is missing Matt Kruse Javascript 4 01-08-2007 09:03 PM
Select box value changes value of hidden field dvwool@ix.netcom.com Javascript 6 04-27-2006 04:38 AM
Selecting a SELECT value BY value? @sh Javascript 16 03-25-2006 09:47 AM
select of select box will select multiple in another box palmiere Javascript 1 02-09-2004 01:11 PM



Advertisments