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?

 

0
LeMerovingian
10/8/2006 2:20:55 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

1 Replies
690 Views

Similar Articles

[PageSpeed] 45

Hi,

you can check if a value exists in DDL with code like this

Dim litem As ListItem = DropDownList1.Items.FindByValue("value_to_look_for")
If litem Is Nothing Then

'goes here if the value wasn't found

End If

What event to use depends on how you bind the grid, basically. You might be able to do it in ItemDataBound in case you set the DDL on row basis in the grid.


Thanks,

Teemu Keiski
Finland, EU
0
joteke
10/8/2006 2:40:24 PM
Reply:

Similar Artilces:

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...

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...

Bind Dropdown list to a key value pair in the web.config
Can anyone guide me on how to Bind a Dropdown list to a series of key:  value pairs in the web.config. Hi greco,You would have to use:this.myDropDownList.Items.Add( ConfigurationManager.AppSettings[ "key1" ] );this.myDropDownList.Items.Add( ConfigurationManager.AppSettings[ "key2" ] );...Good Coding!Javier Luna http://guydotnetxmlwebservices.blogspot.com/ from Villa El Salvador for world! Almost.  If you want the key *and* the value, you need to specify both. this.myDropDownList.Items.Add(new ListItem(ConfigurationManager.AppSettings...

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( Action_DD.Items.FindByText(insertJobRow[JobData.NEXT_ACTION_FIELD].ToString())); but i need to do the above for integer values. Any one know how. Have you tried using the FindByValue() method in place of ...

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 to take value from datagrid dropdown list and put into same datagrid textbox
I have a problem i create a datagrid its showing th data when its run ,i want to edit data by using dropdowmlist and put this dropdownvalue to textbox of this datagrid , any one can do for methankssyed Read up this article - Adding a DropDownList to an Editable DataGrid Hope it helps..Alvin ChooiMicrosoft ASP.NETâ„¢ Enthusiast v1.1 / v2.0, Malaysia Blog : http://alvinzc.blogspot.com...

adding values to the selected value in Dropdown list
 Hi,   I have dropdown box in my page which have some value inherted from the another list box in my page..Now in my second page , i have dropdown box with values and text value and list box... I'll be selecting the one value from the dropdown then i enter the value in text box and click on add button which will add the value in the list box like this i can able to add many value...now if i click on save button for the selected dropdpown item the added values in the listbox should be saved ...like this i add many values for many dropdown item and saved respectivelynow if c...

Comparing Datagrid Values to DataSet/Tables Values
Hi All! I'm stuck and I hope someone can help me - probably an easy answer.  ;-) I'm running VS2003 w/FW 1.1 writing in VB.Net. The setup: I'm using a datagrid(dg) as part of the form that is filled out. Most of the dg fields are textboxes within template columns and are bound from a dataset(ds) that is populated from a sql proc. The issue I'm having is testing each dg row field against its counterpart in the ds (I save the ds between posts to use for change checking). The ds fields are sql types, but the dg fields aren't (they're just simple text boxes). I've tried converting the...

binding values to dropdown list
Hi, I am not sure if this can be done, but let's say I have a dropdown list of names that is populated with certain "active" records from a table.  I only want these active ones to be displayed in the list.  However, there is some existing data that is using the inactive names.  I want to display the inactive name, but only have the active ones available in the list if that name needs to be changed. If I just set the SelectedValue to the item not in the list, I will get the error: Specified argument was out of the range of valid values. Is there a way to displ...

How to bind value to a DropDown list
Hi,I am currently doing a page on which i am retrieving data into a DataList and showing it in TextBoxes and DropDownListBoxes.However, I was unable to bind the value to the DropDownListBox from the database.I am able to bind my textboxes but couldn't do so with DropDow listbox, could you please guide me on how i could achieve that.Another question is, how can I retrieve multiple rows from the database table and display each column of each row in a separate TextBox or DropDownList Box(The value in the database as the selected value for DropDownListBox)Here is my code: 1 <asp:DataL...

DropDown list submits first value not the selected value
I am relatively new to programming and am having a problem with a small project that I am working on.  I have a names drop down list that is created from a database.  When the user selects a name and completes the rest of the form and clicks submit.  All of the data they entered is submitted to a different table in that database.  This is workign correctly for all of the data except the drop down.  For some reason the first value in the drop down is being submitted each time.  Here is the code and any help you can give will be appreciated. Public Class final1 ...

Passing Values from a Web Form to Another Web Form
Hello All! I am trying to pass values from one web form to another web form. I know that there are 3 ways of doing this: queryString, Server.Transfer and Session. I am using the Server.Transfer method. But I am not able to create, in my 2nd web form, an instance of my 1st web form. My 1st Web form is named CallTrack.aspx and my 2nd is named Export.aspx. What I mean is something like this: Public value as CallTrack. I can't create it in my 2nd web form because when the intellisense is displayed, there's no CallTrack in the options. Thanks!   How about using cross-...

How to show value in textbox from selected value in Dropdown list
I have two text box, txtbox1 should be from two field for example i have one dropdownlist where i select item and another txtbox2 i want to put value, when i first time to write manually value in txtbox2 in and selected item from ddl i want to result in concatenate from in txtbox1. for example  I haveif not me.ispostback thenDim cm as new sqlcommand("Select AccMjrid, Names from Accgrp", me.sqlconnection1.open())me.sqldataAdapter1.fill(Dataset1, "Accgrp") Me.cmbAccMajID.DataSource = Me.DataSet11.Tables("AccMajor") Me.cmbAccMajID.DataTextField = "AccName" Me.cmbAccMajID.DataValueField ...

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...

Web resources about - Compare Dropdown list values to corresponding lookup values before binding in datagrid - asp.net.web-forms

'Star Wars: The Force Awakens' Grosses $153.5 Million for Christmas Weekend, Hits $1 Billion Globally ...
Star Wars: The Force Awakens just broke the Christmas weekend box office record with a whopping $153.5 million haul! According to THR , the ...

Chicago Police Accidentally Shoot and Kill 55-Year-Old Mother
Early Saturday morning, the Chicago police accidentally killed Bettie Jones, a 55-year-old mother of five, when responding to a domestic disturbance ...

Massive Tornado Strikes Dallas, Killing At Least 11 People: VIDEO
Shortly after 6 p.m. Saturday, I piled several large pillows from the couch in the bathtub and prepared to take shelter there as tornado sirens ...

Peyton Manning denies using HGH, banned substances
Slate Magazine Peyton Manning denies using HGH, banned substances NFL.com In an intense and emotional denial Sunday morning, Broncos quarterback ...

California firefighters work to contain last stretch of wildfire
More than 400 California firefighters were battling on Sunday to contain a final stretch of wildfire that had caused the partial closure of a ...

Trump Whines To Fox About Clinton 'Playing The Woman Card'
Poor Donald. That mean old Hillary is picking on him for daring to point out that he's a hate-filled, raging sexist. Most of the Sunday shows ...

Washington Redskins QB Kirk Cousins' time has arrived
ESPN Washington Redskins QB Kirk Cousins' time has arrived ESPN PHILADELPHIA Mike Shanahan's friends thought he was crazy for referring to ...

British soldiers aid evacuation in flood-hit northern England
British soldiers helped evacuate hundreds of people from rising floodwaters in the historic city of York on Sunday, after heavy rainfall inundated ...

Pakistani Army Chief Makes for Kabul to Assist Intra-Afghan Peace Talks
Pakistani Chief of Army Staff (COAS) Gen. Raheel Sharif on Sunday headed to the Afghan capital of Kabul to contribute to the peace talks between ...

China adopts first counter-terrorism law
China adopted its first counter-terrorism law on Sunday after early drafts of the bill attracted strong criticism for provisions that may tighten ...

Resources last updated: 12/27/2015 6:26:56 PM