Asp - Duplicate Items In Dropdownlist

Jan 5, 2011

I'm designing a web page with two dropdownlists, one for the Make of a car, the other for the Model, both bound to a database with separate SQLDataSources, and using a distinct statement. I add "All" at the top of both by setting appendDataBoundItems = true and adding items named all. Then when I fill the Make with a querystring all the model items get added twice (but only the databound items).Here's my code:

<asp:DropDownList ID="DropDownMake" runat="server"
DataSourceID="SqlMakes" DataTextField="Make" DataValueField="Make"
AppendDataBoundItems="True" EnableViewState="False" AutoPostBack="True">
<asp:ListItem Selected="True" Value="All">All</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownModel" runat="server"
AppendDataBoundItems="True" AutoPostBack="True" DataSourceID="SqlModels"
DataTextField="Model" DataValueField="Model" EnableViewState="False">
<asp:ListItem>All</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlMakes" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT DISTINCT [Make] FROM [Parts]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlModels" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT DISTINCT [Model] FROM [Parts] WHERE ([Make] = @Make)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownMake" Name="Make"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
'And in the VB file:
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
DropDownMake.SelectedValue = Request.QueryString("Make")
DropDownModel.SelectedValue = Request.QueryString("Model")
End Sub

If I remove the line "DropDownMake.SelectedValue = Request.QueryString("Make")" it doesnt produce duplicates anymore. What is going on?? I swear I've spent more time developing entire iphone app.

View 2 Replies


Similar Messages:

Web Forms :: Remove Duplicate Items From DropDownList

Jun 28, 2012

I would like to know, how to make sure, item with same name do not appeares 2x in the dropdownlist item? 

View 1 Replies

Avoid Duplicate Items When Databound Control Gets Bound Twice?

Feb 1, 2010

How do you avoid duplicate bound items in this scenario: There's a databound control on a page (a DropDownList in this case, though I don't think it matters). It has AppendDataBoundItems set to "true". Somewhere in the code, a DataSource is set and DataBind is called. So this control is bound explicitly. You have a bunch of other things to bind on the page, so you call Page.DataBind.

Your databound control now has duplicate items in it. It was (1) bound explicitly, then (2) Page.DataBind bound it again. Since AppendDataBoundItems was true, the second bind appends to the first, and you end up with double the items. A couple limitations: The explicit call to DataBind on the control is done through some centralized code, and would be painful to change. i really need to bind the rest of the page in aggregate (via Page.Databind()) because there's too many other databound elements to do it individually without writing a ton of individual calls.

I need a method like... Page.DataBindExceptIfTheyHaveAlreadyBeenBoundDuh()

View 2 Replies

Forms Data Controls :: Highlight Color On Duplicate Items In Listview In Vb2005

May 27, 2010

Highlight color on duplicate items in listview in vb2005

View 1 Replies

Web Forms :: Display All Items In Child DropDownList When ALL Is Selected In Parent DropDownList

Sep 6, 2012

protected void DDLzone1_SelectedIndexChanged(object sender, EventArgs e)
{
BindDistrict();
}

[Code]......

here when i click on ALL item from ddlzone1  it just "ALL" item in ddldistrict

i want when i select "ALL" item from ddlzone1 in ddldistrict14 show all data from database

View 1 Replies

Web Forms :: Remove Duplicate Values From DropdownList

Jan 12, 2012

I have hard coded and added items to dropdownlist ie teamsize as 1,2,3 like that.When i load this dropdownlist for edit/update i get duplicate values like this

1
1
2
3
4...

How do i eliminate this duplicate values?

View 1 Replies

C# - Dropdownlist Shows Duplicate Values While Editing A Row In The Gridview?

Jan 11, 2011

Well the dropdownlist has an existing items. I just want the selected gridview record to be displayed in the dropdownlist. The dropdownlist has several DataTextField in string and consist of DataValueField in numeric. The gridview passes a string text to the box which has an equal or same item inside the dropdownlist. Whenever i passed a record from a gridview to be viewed in the dropdownlist it just duplicates the same item. Q: How can i simply pass a text inside the dropdown and just simply display it without adding on the list.

sample item on the dropdown:
--Select--
Account
Savings

after selecting on the gridview and display inside the dropdown:
Account
Account
Savings

(you see the '--Select--' was erase and replace with the selected record)

View 2 Replies

Web Forms :: Group (Remove) Duplicate Values From DropDownList

May 7, 2015

I have a master table relationship, i.e. depending on what is selected in the dropdown list the grid show the relevant data.In the database there are several identical entries for the Position field, for instance there are four marketing managers that have different name. How can i group the identical Position name in the dropdown and when selected the grid should display all marketing managers. Here is the code:

<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="sqlDdl"
DataTextField="ID" DataValueField="Postion">
</asp:DropDownList>
<asp:GridView ID="grid" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="sqlCon" EnableModelValidation="True">

[Code] ....

View 1 Replies

Forms Data Controls :: Delete One Duplicate Record Of Many Duplicate Records

Mar 15, 2010

I have a gridview with delete buttons for each record (I've used AccessDataSource). I have loaded the data in and have many duplicate records.

I just want to use the delete button delete each duplicate record while remains many duplicate records. For example:

I used the following query to load in duplicate records:

SELECT * FROM TableA WHERE ([ControlA] IN (SELECT [ControlA] FROM TableA GROUP BY [ControlA] HAVING (COUNT [ControlA]) > 1)))

ID ControlA PIN# FaceValue Date
delete 76637 128232 1234 5 6/4/2006
delete 72722 128232 1234 5 6/4/2006
delete 76638 234567 2345 10 7/3/2006
delete 72723 234567 2345 10 7/3/2006

What is the query to delete single duplicate record instead of deleting all duplicate records?

View 25 Replies

Dropdownlist - "Cannot Have Multiple Items Selected In A DropDownList.&quot?

Apr 29, 2010

how i handle this problem..Its in hidden filed.

Server Error in '/DentalClaimPrjt' Application.

Cannot have multiple items selected in a DropDownList.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Cannot have multiple items selected in a DropDownList.

Source Error: [Code]....

Line 85: function openPopup2(did)
Line 86: {
Line 87: var hdnClm1 = document.getElementById('<%=hdnCliamid.ClientID%>').value;
Line 88: window.location="Form.aspx?DeleteRSPid=" + did + "&Editid="+ hdnClm1;
Line 89: }

Source File: d:DentalClaimPrjtForm.aspx Line: 87 Stack Trace: [Code]....

[HttpException (0x80004005): Cannot have multiple items selected in a DropDownList.]
System.Web.UI.WebControls.DropDownList.VerifyMultiSelect() +106
System.Web.UI.WebControls.ListControl.RenderContents(HtmlTextWriter writer) +124

View 2 Replies

Dropdownlist With Certain Items In A Different Color?

Mar 22, 2010

I have a drop down list as follows:

[Code]....

[Code]....

View 1 Replies

MVC :: Caching Items For DropDownList?

Jan 20, 2011

I have a dropdownlist that contains items from a database. The set of items are unlikely to ever change. At the moment, whenever a user tries to access the View with the dropdownlist, the code retrieves the data each time from the DB. I would like to change this so that the set of items are cached and load on the application start only.

Could somebody indicate the best mechanism for this scenario? I have read up on Enterprise library which is my current preference, though any alternatives (with reasons) would be welcome.

View 5 Replies

C# - Copy Items From One DropDownList To Another?

Apr 19, 2010

How can I copy items hardcoded from one dropdown box to another keeping the keys and values?

drpTypes.Items.Add(new ListItem("Tipos de Acções", "1"));
drpTypes.Items.Add(new ListItem("Tipos de Combustível", "2"));
drpTypes.Items.Add(new ListItem("Tipos de Condutor", "3"));
drpTypesCreateEdit.Items.AddRange(drpTypes.Items);

View 2 Replies

How To Add List Items To Dropdownlist In A Formview With Vb.net

Nov 26, 2010

I have a dropdownlist in a formview that looks like this:

<asp:DropDownList ID="DropDownList5" runat="server" AppendDataBoundItems="True"
DataSourceID="SqlDataSource6" DataTextField="StaffName"
DataValueField="StaffName" SelectedValue='<%# Bind("LetterName") %>'
Width="155px">
<asp:ListItem Value=""> </asp:ListItem>
</asp:DropDownList>

I am trying to add the value from a textbox which is also in the formview into the dropdownlist as a list item. I currently have this code for it:
Protected Sub Formview1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.PreRender
Dim dropdown As DropDownList
Dim listvalue As TextBox
dropdown = FormView1.FindControl("dropdownlist5")
listvalue = FormView1.FindControl("textbox1")
dropdown.Items.Add(New ListItem(listvalue.Text, listvalue.Text))
End Sub

This code works and adds the new item to the dropdownlist if I have no SelectedValue set for my dropdownlist. However when I set the selectedValue I get the error message:

"'DropDownList5' has a SelectedValue which is invalid because it does not exist in the list of items.

Parameter name: value"

This is the bit I dont understand because the value does now exist in the list of items as it was added in from the textbox value. Does it try to do the selectedValue before adding my list item? If so how can I add the list item first, or do I need to set the selectedValue in the code after adding the list item?

View 3 Replies

Web Forms :: Lot Of Items In A Databinded Dropdownlist?

Jan 14, 2010

i have a database table with lot of records > 17000what is the most efficient way to let user to choose between one of the records- 1 dropdownlist with all the 17000 record ?- 1 textbox with autocomplete and a webservice that return the list of the records ?

View 3 Replies

Web Forms :: Set A Hyphen To All Items In Dropdownlist?

Jan 10, 2011

I have a dropdownlist with items. dropdownlist got it from a List<string> object.

Now i want to set a hyphen for all the items. so i looks like this:

- a
- b
- c

Does anyone know a way to do this?

View 5 Replies

Ie Dropdownlist Won't Show All Items And Firefox Will?

Apr 14, 2010

On the home page as I on work, I have a dropdown list which act as a menu. But in Internet Explorer can not figure out how to display all text in my dropdown list How it looks in Internet Explorer

How it looks in firefox, chrome and opera Do you know how to do so that Internet Explorer also displays all the text in my dropdown list like in firefox and the other

View 2 Replies

C# - DropDownList Items Are Reset On SelectedIndexChanged?

Sep 17, 2010

I have a cascading dropdown list on my page. The first dropdown contains a list of events. The second dropdown contains a list of attendees. When an event is selected, an AJAX call is made to get the list of attendees for that event, and populate the second dropdown.

My problem is that for the attendees dropdown, I want the user to be redirected to a URL on the SelectedIndexChanged event, with the selected value in the query string. But on the SelectedIndexChanged event, all the items in the second dropdown are reset. Here's my code:

<script type="text/javascript" language="javascript">

$(document).ready(function()
{
$('#<%= ddlEvents.ClientID %>').change(function()
{
$.ajax({

[Code]....

When the SelectedIndexChanged event is hit, ddlAttendees is empty.

Does anyone know how I can keep the items in ddlAttendees?

View 2 Replies

MVC :: Populating Items In A DropDownList From The Model

Mar 23, 2011

Using MVC2, I want to know how you add the options of a dropdownlist from a database. I have several lookup lists so I will need to do this many times. I'm stuck on part 5 of the MusicStore (which is using MVC3) at this part

[Code]....

Alternatively if someone could recommend an MVC2 tutorial which covers drop lists.

View 9 Replies

.net - Add Custom Object To DropDownList Items?

Jul 11, 2010

I'm using DropDownList within my WebApplication. I need to keep additional piece of information with each Item on list. How can I achieve this?

View 3 Replies

C# - Insert Newline Between The Items Of Dropdownlist?

May 15, 2010

I want give some space between the items of the dropdownlist. is it possible?

ddl:

item1
item2
item3

View 3 Replies

Dropdownlist Javascript Change Items?

Aug 25, 2010

I have dropdownlists in Gridview. I need to dinamicly change content of dropdown on client with javascript. Ok, I know to do that. But the problem is when I send data to server changes in dropdownlist does not see. On server I have old items. How can I change items in dropdown on client with javascript and than see that items on sever when postback data?

View 5 Replies

Web Forms :: Compare Items Of Two DropDownList

May 7, 2015

how to count the common data from two dropdownlist control.ex..

1st dropdownlist have 1 2 3 4 

2 nd dropdownlist have 3 4 5 

so the count of common value is 2 (3 4)..how to calculate this.

View 1 Replies

Web Forms :: Group Items In DropDownList

Jan 24, 2016

Category and Sub Category in single Drop Down List DDL example with showing subcategory inside Main Category...

View 1 Replies

Dropdownlist Is Not Accepting New Items When Added Dynamically?

Dec 24, 2010

On adding items in it ,shows an error: "Dropdownlist does not allow multiple selection."But when i tries to print the selected item it shows null exception.

View 6 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved