473,626 Members | 3,304 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting HtmlSelect SelectedIndex using a value

This is my code:

HtmlSelect m = new HtmlSelect();
m.ID = "m1";
m.DataSource = dvBasic; //DataView created elsewhere
m.DataTextField = "value";
m.DataValueFiel d = "key";
m.Value = "2"; //<----NOT WORKING
ctrlsPlaceHolde r.Controls.Add( m);
this.DataBind() ;

The docs state in relevant part:

HtmlSelect.Valu e: "... or sets the SelectedIndex property of the
control to the index of the first item in the list with the specified
value."

Shouldn't my code set the SelectedIndex to, say, 1, if "2" is the
value of the list item at index 1? It's not doing this, but instead
just displaying the first list item.

Thanks for any help!

Brent

Aug 25 '06 #1
1 2235
try setting the value after calling the databind method.

Regards,
Augustin
http://augustinprasanna.blogspot.com

"wr********@gma il.com" wrote:
This is my code:

HtmlSelect m = new HtmlSelect();
m.ID = "m1";
m.DataSource = dvBasic; //DataView created elsewhere
m.DataTextField = "value";
m.DataValueFiel d = "key";
m.Value = "2"; //<----NOT WORKING
ctrlsPlaceHolde r.Controls.Add( m);
this.DataBind() ;

The docs state in relevant part:

HtmlSelect.Valu e: "... or sets the SelectedIndex property of the
control to the index of the first item in the list with the specified
value."

Shouldn't my code set the SelectedIndex to, say, 1, if "2" is the
value of the list item at index 1? It's not doing this, but instead
just displaying the first list item.

Thanks for any help!

Brent

Aug 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
381
by: Jonathan | last post by:
Hi everyone, I have a problem with a HtmlSelect control that I am loading dynamically in javascript. Here is my code: <asp:DropDownList id="MyDropDownList1" onChange="LoadContent(this);" runat="server"> <asp:ListItem value="0">&nbsp;</asp:ListItem> <asp:ListItem value="1">MyChoice1</asp:ListItem> <asp:ListItem value="2">MyChoice2</asp:ListItem> </asp:DropDownList>
7
20762
by: charliewest | last post by:
Using .Net CF, i have created a 2 dimension ArrayList, and "binded" this list to a ComboBox control using the "DataSource" property. I have set the DisplaySource and ValueMember properties as well. The control populates well, both the display values, and selected values. However, when i try to "set" the SelectedValue or SelectedIndex properties, nothing happens.... The default blank value in the ComboBox is always selected. My code is: ...
0
932
by: Suhail A, Salman | last post by:
Dear All, I placed a HtmlSelect control on a web page and set "Run at Server", the objective of this list box is that the client adds all his accounts to this text box, and because this is a client side operation / no server intervention is required, I wrote the JavaScript below to add account number entered in a text box to the list control, this works fine, the client can enter all his accounts to the html select control, the problem...
1
2264
by: Suhail A, Salman | last post by:
Dear All, I placed a HtmlSelect control on a web page and set it to "Run at Server", the objective of this HtmlSelect control is that the client adds all his accounts to a text box, and because this is a client side operation(no server intervention is required), I wrote the JavaScript below to add account number entered in a text box to the list control, this works fine, the client can
2
5807
by: Stephen Miller | last post by:
When I dynamically populate a HtmlSelect combo box, the Value property consistently fails to return the item selected, defaulting instead to the first item in the list. For example: Protected WithEvents Fruits As System.Web.UI.HtmlControls.HtmlSelect Protected WithEvents Results As System.Web.UI.WebControls.Label Protected WithEvents Button1 As System.Web.UI.WebControls.Button … Private Sub Page_Load(ByVal sender As System.Object, ByVal...
4
9650
by: Emil | last post by:
Can somebody tell me what would be the syntax for having an if statement and setting the selected index of a radiobuttonlist? This is my first project using ASP.net and I use C#. I have a repeater with like a table layout and in the last column I want to have three radio buttons (for each row in repeater). The value of the radio button should be calculated from a value from the dataset. How can I do that? When I try to use a variable...
3
2090
by: Joe | last post by:
Hello All, I am populating an HtmlSelect control's Items property with four list items. The HtmlSelect control is contained in a user control which is dropped into a placeholder on the web form. When the page is rendered, the control is empty. Here is the code: In the web form: Dim UControl As AugmentedDropDownList =
2
1552
by: mirlisa | last post by:
I'm using an HtmlSelect (runat=sever). I add the items programmatically and I also add a custom attribute to each listitem because I need to track an additional field value. I'm having a problem getting that attribute value upon postback. I keep getting a null reference error. I was under the impression that the attribute collection is saved in viewstate. My code to get the attribute value is:
18
2114
by: Academia | last post by:
I let the use modify the text of a combobox and then I replace the selected item with the new text (in Keyup event). But if he sets the Text property to an empty string ("") that sets the SelectedIndex to -1. Do you have any suggestion for getting around this problem?
0
8269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8203
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8711
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8642
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5576
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4094
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4206
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1515
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.