Hi,
I am using FindByText method of dropdownlist to change the selected item in a dropdownlist like this:
DropDownList1.I tems("mySelecte dText").Selecte d = True
It doesn't seem to be doing the trick. I have this piece of code in OnSelectedIndex Changed event of the dropdownlist.
Can anyone tell me why it's not setting the selected item?
Thanks,
AK 3 10124
The DropDownList's Items collection does not accept a string or a ListItem name as an argument. If you only know the text of the item you wish to have selected you can use:
DropDownList1.S electedValue = DropDownList1.I tems.FindByText ("text").Val ue
hope this helps,
John
"AK" wrote: Hi,
I am using FindByText method of dropdownlist to change the selected item in a dropdownlist like this:
DropDownList1.I tems("mySelecte dText").Selecte d = True
It doesn't seem to be doing the trick. I have this piece of code in OnSelectedIndex Changed event of the dropdownlist.
Can anyone tell me why it's not setting the selected item?
Thanks, AK
HI John,
Thanks for responding..But in a hurry, I think I missed typing FindByText.
Instead of setting DropDownList1.I tems.FindByText ("mySelectedTex t").Selected = True, I also tried the exact same line of code that you gave below. But the surprising and as well as annoying thing that I noticed is that, if I hardcode the text parameter, it works fine but if I have that value in a variable, it doesn't set the selected value. I also tried trimming the text before passing it to the FindByText method. I even printed out the variable value to the browser and it's exact same thing as I hardcoded.
Could you tell me what could be the reason for this?
Thanks,
AK
"John Sivilla" wrote: The DropDownList's Items collection does not accept a string or a ListItem name as an argument. If you only know the text of the item you wish to have selected you can use:
DropDownList1.S electedValue = DropDownList1.I tems.FindByText ("text").Val ue
hope this helps, John
"AK" wrote:
Hi,
I am using FindByText method of dropdownlist to change the selected item in a dropdownlist like this:
DropDownList1.I tems("mySelecte dText").Selecte d = True
It doesn't seem to be doing the trick. I have this piece of code in OnSelectedIndex Changed event of the dropdownlist.
Can anyone tell me why it's not setting the selected item?
Thanks, AK
Hi AK,
No if the values are the same and you are sure of that, then there is no reason that it shouldn't work. Try something like this.
Dim strValue as String = "text"
DropDownList1.S electedValue = DropDownList1.I tems.FindByText (strValue).Valu e
and then try replacing strValue with "text".. They should both work. If it doesn't please post some code; there has to be something going on!
thanks,
John
"AK" wrote: HI John,
Thanks for responding..But in a hurry, I think I missed typing FindByText. Instead of setting DropDownList1.I tems.FindByText ("mySelectedTex t").Selected = True, I also tried the exact same line of code that you gave below. But the surprising and as well as annoying thing that I noticed is that, if I hardcode the text parameter, it works fine but if I have that value in a variable, it doesn't set the selected value. I also tried trimming the text before passing it to the FindByText method. I even printed out the variable value to the browser and it's exact same thing as I hardcoded.
Could you tell me what could be the reason for this?
Thanks, AK
"John Sivilla" wrote:
The DropDownList's Items collection does not accept a string or a ListItem name as an argument. If you only know the text of the item you wish to have selected you can use:
DropDownList1.S electedValue = DropDownList1.I tems.FindByText ("text").Val ue
hope this helps, John
"AK" wrote:
Hi,
I am using FindByText method of dropdownlist to change the selected item in a dropdownlist like this:
DropDownList1.I tems("mySelecte dText").Selecte d = True
It doesn't seem to be doing the trick. I have this piece of code in OnSelectedIndex Changed event of the dropdownlist.
Can anyone tell me why it's not setting the selected item?
Thanks, AK This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Maziar Aflatoun |
last post by:
Hi everyone,
I am trying to select an item in my DropDownList (Everything on 1 .aspx
page) and it gives me the following error message. Has anyone encountered
this problem before? or any idea how I can resolve it? (In this case I want
to select the Canada from the country list)
SqlDataAdapter daCountry = new SqlDataAdapter("SELECT * FROM...
|
by: mg |
last post by:
I have a DataGrid (WebForm - C#) that has a template column that contains a dropdownlist named "DdlTest"
In DataGrid1_UpdateCommand, the lin
DropDownList ddlTest = (DropDownList) e.Item.FindControl("DdlTest")
enables me to work with ddlTest - with, for example, ddlTest.SelectedValu
However, in DataGrid1_EditCommand,...
|
by: George Durzi |
last post by:
When my datagrid is in edit mode, one of my columns is edited using a drop
down list.
I'm able to bind the DropDownList to a DataSource when in edit mode.
HOWEVER, I can't preset the DropDownList's value when the Edit button is
clicked for that row inside the datagrid.
Here's a simplified version of my datagrid:
<asp:datagrid...
|
by: huzz |
last post by:
How do i make a dropdownlist selected value based on the value i retrive from
the database.
Basically i have an edit page and like to display the default value in a
dropdown list from the database.
for example: if the ddl_value is 2 from the database i want the second list
item to be selected by default.
|
by: Tim::.. |
last post by:
Can someone please tell me how I go about preselecting an item in a drop
drown list when I click the Edit Command in a datagrid?
I have tried the following but it doesn't work for me!
I would be really grateful for any assistance!
Thanks
| |
by: Chris Kettenbach |
last post by:
Good morning all,
I am sure this has been asked but I did not see anything.
I have a datalist control. In the edititemtemplate I have a dropdownlist.
I know on the itemdatabound event is where I can set the dropdownlist
selectedindex. How do I set the correct value?
private void lstDegrees_ItemDataBound(object sender,...
|
by: pleaseexplaintome |
last post by:
Hi all,
I have a datagrid with a dropdownlist and would like to have the
dropdownlist display a database value correctly while the grid is in
edit mode.
I have a templatecolumn as follows:
<asp:TemplateColumn HeaderText="New Route">
<HeaderStyle Width="0.5in"></HeaderStyle>
|
by: davidson1 |
last post by:
Hello to Everybody,
I have a dropdownlist by name "Subject" which contain C,C++,Java,Php
which is added by the following way
subject.items.add("C")
subject.items.add("C++")
subject.items.add("Java")
subject.items.add("Php")
|
by: stevem2112 |
last post by:
I have a datagrid with 2 Template columns. One column has
DropDownLists and the other has Textboxes. I bind each DDL in the
ItemCreated event. This datagrid is inside a UserControl that is
inside a user control (long story). Anyway, the user clicks a save
button on the parent control to initiate the postback. The parent then
calls a Save...
|
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...
|
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. ...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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...
|
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |