?
Solved

Databound DDL not keeping all list items

Posted on 2007-10-07
2
Medium Priority
?
291 Views
Last Modified: 2010-04-23
I have a ddl, which is not initially bound to a datasource with 4 listItems. User selects one list item, then clicks the save button, which inputs the selected item into database. When I recall the selected item back to the ddl on page load, I have the ddl databound, and it recalls the item that was selected just fine, but it does not show the other list items in the ddl. I need to have all the items still available, in case the user needs to change their selection.

Here is my code:

Script:

Dim Adapter As New SqlDataAdapter("SELECT * FROM Orders Where OrdersID = " & list1.SelectedItem.Value, "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Client.mdf;Integrated Security=True;User Instance=True")

Dim Dataset As New DataSet

Adapter.Fill(Dataset, "Orders")

Me.Representing.DataMember = "Orders"

Me.Representing.DataSource = Dataset

Me.Representing.DataTextField = "Representing"

Me.Representing.DataValueField = "OrdersID"

Me.Representing.DataBind()

 Content:

<asp:DropDownList ID="Representing" runat="server" Height="18px"

Font-Size="X-Small" Width="129px">

<asp:ListItem Value="Plaintiff">Plaintiff</asp:ListItem>

<asp:ListItem Value="Defendant">Defendant</asp:ListItem>

<asp:ListItem Value="Petitioner">Petitioner</asp:ListItem>

<asp:ListItem Value="Respondent">Respondent</asp:ListItem>

</asp:DropDownList>
0
Comment
Question by:mlg101
2 Comments
 
LVL 15

Accepted Solution

by:
Solar_Flare earned 2000 total points
ID: 20032146
From your description I would say that you should not be using Databinding for this - what happens is that when you bind the DDL all existing items are cleared and new items are added based on the bound object. If you change it so that instead of databinding you set the selectedText property then it should leave the list intact but change the selected item.

eg

Dim Adapter As New SqlDataAdapter("SELECT * FROM Orders Where OrdersID = " & list1.SelectedItem.Value, "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Client.mdf;Integrated Security=True;User Instance=True")

Dim Dataset As New DataSet

Adapter.Fill(Dataset, "Orders")

dim SelectedVal as String = Dataset.Tables(0).Rows(0)("Representing").ToString()

Representing.SelectedText = SelectedVal


you may need to change SelectedText to SelectedValue depending on how you are using the DDL
0
 
LVL 1

Author Comment

by:mlg101
ID: 20032287
Thank you! Worked great!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question