Setting a dropdownlist value based on a value in a Database

I have a page that allows users to create a user account.

The aspx has various dropdowns that I populate by binding the dropdownlist to a dataset.
OK so far?
However, I also want a page where the user can edit their I need to be able to set the selected value based on what is saved in my user table and I also need to add the extra entries.
Anyone know how I can do this easily.
Do I need to join on my user table and my table that has all the various categories in order to get the selected value and add my other values??
8/10/2003 3:16:08 AM 93655 articles. 6 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 25

For selecting the correct value you can use the DropDownList::Items::FindByText or DropDownList::Items::FindByValue methods and set the Selected property to the Item.

For filling up with the additional values, you can call DataBind() and after that add the items you need to the Items collection using ListItem class.
8/10/2003 5:40:00 AM

Similar Artilces:

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

DropDownList value selected base on database value?
Hi, is there anyway how I can allow my dropdownlist (on pageload event) to select the value base on the value found in the database, in addition I also want the dropdownlist to contain other values too however the selectedValue must be the one found in the database. Sorry if it sounds confusing. I'm using VB.NET 2003 with ASP.NET Thanks. Hi,Whatever you want to get selected for your dropdown use following code.if(dropdownid.items.findbyvalue("value") != null){    dropdownid.items.selecteditem = false;    dropdownid.items.findbyvalue("value").selected = t...

DropDownList Initial Value set from Database col value
How to set the value(text) in a DropDownList to the selected record (row,colum data) so that the DropDownList doesnt just keep opening to the top of the list. Does anyone know of any good articles that cover How to set a DropDownLists initial Value to the current selected database data. Seems like this would be common. A user selects a row in a DataGrid (by using a dataReader), and the user is taken to another page to update data (text boxes). But the use must select a value from a DropDownList(s). How does one code so that when the page_loads or someplace.. that the Value(text) sitting i...

Set default in dropdownlist based on value from database
After retrieving a value from a field in a table, I would like to set the default value in a dropdownlist based on the retrieved value. Eg. if the retrieved value is 'MR.', the default value is also 'MR.' Any advice? Thanks   If your dropdownlist is bound to a datasource then you should be able to use the 'SelectedValue' property to set a default value, e.g: <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataValueField="Col1" DataTextField="Col2"  SelectedValue='<%# Bind("Col1") %>'>   Thanks northside. Got it w...

Hiding a web form field based on database value.
  Hi, i want a textbox to be hidden based on the user access ID, and if the admin has clicked on a checkbox which makes it deactivated. I have the following; Code behind which displays all the fileds;private void DisplaySelectedRecord(DataView dv) { //populate the controls on the page to show the data on the page controls  this.txtMA_Code.Text = dv[0]["MA_Code"].ToString().Trim();   this.txtRate.Text = dv[0]["Rate"].ToString() ;if (dv[0]["Rate_Active"] != null && dv[0]["Rate_Active"] != System.DBNull.Value)this.CheckBox1...

How conditionally set the checkbox visiable base on a value form the database
I have created a datagrid the code following: Protected WithEvents CheckBox1 As System.Web.UI.WebControls.DataGridItem Sub ItemList_ItemDataBound(ByVal source As Object, ByVal e As DataGridItemEventArgs) If (e.Item.ItemType = ListItemType.Item Or _ e.Item.ItemType = ListItemType.AlternatingItem) Then If Convert.ToString(e.Item.DataItem("Method")) = "" Then _ e.Item.ForeColor = System.Drawing.Color.Red If Convert.ToString(e.Item.DataItem("Method")) = "" Then _ ...

compare dropdownlist value to database value
I'm new to I use a dropdownlist as a navigation menu. When i select one of the customers in the Customers dropdownlist, it will check whether the dropdownlist value is equal to the value in database. Then it will link to another web page, called Outlets.aspx which contains the Customers outlets information. Below is the code i use to bound data into dropdownlist. I have no idea how to compare the dropdownlist value to database value. Anyone can help?Dim cn1 As New OleDbConnection(strConn) Dim da1 As New OleDbDataAdapter("select * from Customers or...

Hello, I'd like to set the value of a DropDownList based on a value of another field in the DataGrid.These values are from different <columns>.The first value shows up just fine in the "BoundColumn".But, the one I want to set in the TemplateColumn isn't working.Can someone take a look at my code snippet and see what I'm doing wrong? The Control I'm trying to set is called "ddlBenchStart".I'm trying to get the value from the "BenchStart" column.The values in "BenchStart" would be "Bench" or "Start&...

Setting a label value to a dropdownlist selected value
I am trying to set the value of a label to the selected value from a hidden dropdown list. This code is not working and the label value remians at its default. Any ideas? Thanks very much. Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Dim mylabel As Label Dim myddl As DropDownList If (DetailsView1.CurrentMode = DetailsViewMode.ReadOnly) Then mylabel = DetailsView1.FindControl("Label1") myddl = DetailsView1.FindControl("DropDownListViewOffice") mylabel.Text = myddl.SelectedValue.ToString End If I have now put this code in the Page_Load su...

<%@ Page Explicit="True" Language="VB" Debug="True" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <HTML> <Script Runat="Server"> Dim aConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" _ & server.mappath("Group17.mdb") Sub Page_Load(Sender As Object, E As EventArgs) Dim aConnection As OleDbConnection Dim aQuery, bQuery As String Dim aDataReader, bDataReader As O...

Setting the value of a RadioButtonList based on a value in my sql table.
Hi folks, From a Sql database table I'm trying to display a RadioButtonList with two text values, "Buy" and "Sell". The actual numeric values in my table are 1 (Buy) or 2 (Sell). The name of the column in the table is "buy_sell". So how do I set the SELECTED="TRUE" property in the ListItem based on the value of my buy_sell column ? <asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1" OnInit="FormView1_Init"> .. .. <EditItemTemplate> <td><asp:RadioButtonList  DataSourceID="ObjectDataSource1" DataValueField="buy_sell" DataTextField...

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

Setting the Parameter Value to the Property Value of a Web Control
I want to filter my DetailsView with a declarative parameter. In my case, I am setting the SqlDataSource's parameter values based on the value of 2 TextBox controls on the page. I have a SP that does a SELECT based on 1 of the parameters passed in (either an ID or phone number). Param Name          Value MemberID          TextBox1.Text Phone               TextBox2.Text I want to assign a default value of 'null' for b...

Need value for DropDownList Listitem to return all values in database
Hi All, Many thanks for all the help thus far.  In short, here's my problem: I am passing controlparameters (from DropDownLists) to my SELECT statement.  Here's the DropDropDownList: <asp:DropDownList id="status_DropDownList" runat="server"><asp:ListItem Value="Open">Open</asp:ListItem><asp:ListItem Value="Closed">Closed</asp:ListItem><asp:ListItem Value= ??? > Get ALL records </asp:ListItem></asp:DropDownList> What value would I assign the Get All records that would return...

Web resources about - Setting a dropdownlist value based on a value in a Database -

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 12/12/2015 12:10:41 AM