Dropdown woes. Need to db value to correspond with dropdown value

I have a dropdown that I need to have set to the selected index of a value thats returned from the DB, an integer that represents the userID.  I have the value returned fine but I' struggling to convert it into the number it needs to be to correspond with the dropdown index.

I can do it with text items with the following: -
Action_DD.SelectedIndex = Action_DD.Items.IndexOf(
but i need to do the above for integer values.
Any one know how.
12/18/2003 11:41:53 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

5 Replies

Similar Articles

[PageSpeed] 14

Have you tried using the FindByValue() method in place of the FindByText() method?
Jamie Kindred, CGA, MCSD
12/19/2003 2:25:41 AM
Yeah I tried that!! Kept returning -1
12/19/2003 2:41:41 AM
Not sure if IndexOf is a good use in the example you gave.

ddlTmp.Items.FindByValue(ds.Tables(0).Rows(0).Item("iUserID").ToString()).Selected = True

You might also want to make sure that the control has been created before you try to find the the userid in the dropdown list. If you are trying to find the value before the control was recreated either thru the viewstate or by binding to a database again then it won't be any good.
Have you tired moving that code to someplace like the Page_Prerender?
Hope this helps.
12/19/2003 4:47:50 AM
Thanks for your help but the example you gave is the reverse of what I'm trying to do.  I'm not trying to get the value from a selection.  I simply want the drop down to have its selected index value that of the value returned from the db.  I.E a user has already selected and submitted a value from the dropdown and saved to db, I now want to return the value back to the drop down.
1/1/2004 8:53:07 AM
Try this one 

Dim itmList As New ListItem()
If Not ds.Tables(0).Rows(0)("Fieldvalue") Is System.DBNull.Value Then
itmList = Me.cboState.Items.FindByValue(ds.Tables(0).Rows(0)("Fieldvalue") & "")
If Not itmList Is Nothing Then
itmList.Selected = True
End If
End If

ds DataSet contains value you are getting from the database.
~ Firoz Ansari
Pune, India
Why product testing is important?
1/1/2004 2:14:27 PM

Similar Artilces:

dropdown selected value and dropdown no value saved
 is there any way the selected value is selected already when i try to edit the gridview ... and another thing... when i edit this dropdown.. no value was being saved... what is wrong or missing.. please help... i almost spend two days on this problem...i've read many post about this.. but still i didn;t get it... please help///  <asp:TemplateField HeaderText="Unit" SortExpression="UnitID">                          &...

cascading dropdown set it's value only once but not on subsequent postbacks,web service recieve the value but can't set in dropdown
i have a dropdown named uxcommunity which is a dropdown and contain text in format ##-####-#### . and 2 more dropdowns province and district where province filters district. i get the first 2 characters ##  for session("province") and #### for session("District") and i have button to do the postback. first when the form loads and i click the button it get the value and select appropraite items in to dropdown province and district. but when i change the province dropdown content and district dropdown content and click the button , session will take correct...

hide only the dropdown value while selecting the another dropdown value
 hai  friend i am using two dropdown list if i select one dropdownlist the another dropdownlist value must be hidewhat can i do for this     Ramesh.Dhttp://rameshduraikannu.blogspot.com  u can do that using javascript..function Hide(){ var drop1 = document.getElementById('<%=dropdownlist1.ClientID%>')  var drop2 = document.getElementById('<%=dropdownlist2.ClientID%>')  if(...

How to use values from two dropdown lists to get the value for a third dropdown?
I have three dropdown lists.  One for Office, one for Department, and a list of employees.   There is no relationship in the database between office and department.  The relationships are to the employees.  What I need to do is take the selected values from Office and Department, and run a query to get the list of employees who match both parameters (Office & Department).  Here's my code for the three dropdown lists.  How do I "connect" Office & Department to populate employees?  code from my vb.net page    for the ...

How do you grab dropdown values from Web Form ?
I want to grab the selected value and store into a parameter so far Im doing this but the selected value is not storing Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@TRA_Quarter", System.Data.SqlDbType.NVarChar, 2, "@TRA_Quarter")) 'define quarter other parameter SqlCommand1.Parameters("@TRA_Quarter").Value = ddlQuarter.SelectedItem.Value 'insert Training Quarter from form into parameter Redeem. Are you repopulating the data of the combo box on post backRaghu Vangala http:/...

Drop down list in Form view returns error when value in bound field (data binding
I get the following error when I click edit to edit the details in the web form:'ddlUserRestrictionType' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: value  I would like it to accept any value which currently exists in the database. Is this easily achievable? With what you've posted, all I can tell is that you are trying to set the SelectedValue of a ddl to a value that does not exist in the list.  It would be helpful if you can post some code and the expected values of this control.~ Timwww.bucketo...

How to set a dropdown value in a form based on a value read from a database?
We wish to populate a form based on information read from our database.One of the controls is a dropdown list. We first fill up the ddl from a table of about 60 values. Then we read a value from a different table that was saved data earlier to see which of the 60 values was picked. We wish to show the user that value in the dropdownlist when we display the form. How can we do this?For example, we fill the dropdown list with school course codes (French, German, Math, etc.) , then wish to read a different table in the database and select the dropdown item based on what we r...

Compare Dropdown list values to corresponding lookup values before binding in datagrid
how can i do this? does anyone know which event I would do it in?the problem is that the items in the lookup list (of users) keeps changing because it is stored in a database. i need to check that the values match so that the dropdownlist doesn't crash when the SelectedValue can't be found, hence if the value doesn't exist i can set it to something else.any ideas?  Hi,you can check if a value exists in DDL with code like thisDim litem As ListItem = DropDownList1.Items.FindByValue("value_to_look_for")If litem Is Nothing Then'goes here if the value wasn't f...

problem in selecting value from dropdown inside a repeater and inserting the selected value inside db
there is  checkbox and drop down inside my  item template of repeater in one page.Based on that drop down and check box selection calculation will be done in another page which will be inserted inside a db.I cannnot fetch the value from the dropp down in my save page  and as a resut data cannot be inserted inside db. plz help!!  <asp:Repeater ID="rptmenproduct" runat="server" >                      <HeaderTemplate>    <...

Sorting microsoft report on web form from dropdown list values
Hi, I have a Microsoft report viewer tied into an object data source. The object data source is pointing to a data table .xsd file. I have setup my filtering using parameters in SQL and tying those parameters to controls on my web form to filter the report. That is working fine, however I also want to be able to use a dropdown list to select the fields to sort the report by, as well as what order ascending or descending.  I know you cannot use parameters in the Sort By column in SQL so I have been trying to use the SORT BY CASE statement then pointing those parameters to the dropdowns...

Need multi-valued dropdown list but can't use standard value + text solution
I have a situation where I am filling a dropdown list from a datasource that is created from a Web services call (specifically, city-state pairs based on a zipcode lookup). The text field is 'city' however I can't use the value field for 'state' because in virtually all cases the state will be the same--although I can't count on this always being the case. (Having the same value for multiple entries in the list gets the dropdown list really upset, apparently!) So, what is another option as it does not appear that we can add keys to lists (which would solve the problem, of course)? Thanks! D...

dropdown list filled via DB, need to add another value
Hi, I have a dropdown list that is databound to a DB.  I need to add 1 additional value to the dropdown list.    Where do I place the code to do this? I tried Page_Load but that didn't seem to have any effect. TIA,Dave   Where/How are you loading the DropDownlist (what event)?David WierMCP/ASPInsiderASPNet101.com - where to look first!Please Vote for ASPNet101 - 'Best Community Resource'!Control Grouper - easily control properties for multiple controls with one control!Calendar Express - The Best HTML Calendar Generator on the web!(Please 'Mark as A...

Need to populate Textbox dynamically with values from DB according to the selected dropdown
Ppl,  I have com across answers for this question , which did not suit my requirements.  Hence posting here, pls help me.   My situation is, I have a dropdownlist which is going to display events that are about to take place. and when I select an event, I have to get the start and finish dates of that particular event and to display the same in two textboxes. Problem is, the dropdownlist is populated dyanmically inside a form(so, no selected_indexchange event for it), likewise i have the textboxes too....   any help would be appreciable. Thanks. im prett...

new to .net, need help setting db values from checkbox's then retrieving value to a label control
Hi, Being new to asp.net i know this possible i just can't quite get it right!  I need a page with 5 checkbox's that when submitted sets the bit values in DB fields to checked. Then i need another page that retrieves the records of the checkboxes, but instead of having the db pre-set checkboxes on the second page i want it to turn on label web controls depending on if the check box is set.. I hope that makes sense?!! Can anyone point me in the right direction or to a suitable tutorial? Thanks in advance Ben Excellent article here.http://www.heliosfx.com...

Web resources about - Dropdown woes. Need to db value to correspond with dropdown value - asp.net.web-forms

Three quarters of Australians believe climate change is real; views on cause correspond with world view ...
Three quarters of Australians believe climate change is happening, but conservative voters are more likely to believe it is a natural phenomenon. ...

Talk on Twitter corresponds to higher TV ratings
A new Nielsen study shows a correlation between people tweeting about a certain TV show and an increase in that show's ratings.

Debris number corresponds to Boeing 777 component - CNN.com
Boeing investigators are confident that debris found on a remote island comes from a 777 aircraft, source says.

Number on Reunion Island debris corresponds to Boeing 777 component
An international team of aviation experts is trying to determine if that airplane part comes from Malaysia Airlines flight 370, a Boeing 777 ...

The Strength Of The Economy Corresponds To How Often We Cut Our Hair
The dearth of split ends sprouting from the heads of Americans means more than that we're obsessed with our looks, it's an indication that our ...

Top EPA official used private email account to correspond with environmental groups
EPA Region 8 Administrator James Martin apparently corresponded with the Environmental Defense Fund

Chipotle Raises SF Prices to Correspond With Wage Hike
... wage increase. The company's San Francisco locations have raised prices by as much as 14 percent, reports Investor's Business Daily , corresponding ...

Wizard Hoodie With Light And Sound Effects That Correspond To Different Spells You Can Cast
The Technomancer 2.0 Digital Wizard Hoodie is a $120 hoodie available from ThinkGeek (previously an April Fools' joke that they made real). The ...

Number Of Twitter Followers Does NOT Correspond To Influence: STUDY
Previously, a person's influence on Twitter was thought to correlate directly to the number of followers. Advertisers even pay popular Tweeters ...

Was 50 Cent's Awful First Pitch A PR Stunt? Blooper Corresponds With New Album 'Animal Ambition' Release ...
Timing of 50 Cent's first pitch before Tuesday night's New York Mets game raises questions about whether the whole incident was a PR stunt.

Resources last updated: 12/26/2015 7:17:56 PM