.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

dropdownlist bound to sqldatasource adds items instead of replacing on change

Posted By:      Posted Date: August 26, 2010    Points: 0   Category :ASP.Net


I have a series of dropdownlists on webform in ASP 4.0. The first drop down is filled upon load, and then when a user selects a value from that list, it populates the second dropdown. To accomplish this, I have a SQLdatasource with a parametersource of the first drop-down list control. This works great, except when a user changes their selection from the first drop down. It performs the query, but then adds the list of items to the ones that were already there from the previous selection, instead of replacing it with the new data. Here is the code:

 <asp:DropDownList ID="ddlMajor" runat="server" DataMember="DefaultView" 
      DataSourceID="SqlDataSource1" DataTextField="majortext" 
      DataValueField="majorkey" AppendDataBoundItems="True" AutoPostBack="True">
         <asp:ListItem Value="0">Select Major</asp:ListItem>
<asp:DropDownList ID="ddlReq" runat="server" DataMember="DefaultView" 
      DataSourceID="SqlDataSource2" DataTextField="req" DataValueField="admreqkey" 
            AppendDataBoundItems="True" AutoPostBack="True">
                <asp:ListItem Value="0">Sel

View Complete Post

More Related Resource Links

dropdownlist javascript change items


I can't find solution for this problem for very long time:

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?


jQuery: Styling DropDownList Alternating Items (Rows)

In the following example, I will show how you can style any asp:dropdownlist very easily.

The example demonstrates how you can change alternating row items background color, using the fadeTo() to add a nice touch in the dropdownlist. You can change alt rows with a couple lines.

SqlDataSource how to change the stored procedures at run time



Is it possible to change the select, insert and update stored procedure of an SqlDataSource at run time. I don't mean to change the definition of the stored procedure, but I mean to change the assignment, i.e. To change the select stored procedure from "selectSP1" to "selectSP2" at run time. Is it possible?



How to handle Active and inactive items in the dropdownlist?


It is a general ASP.NET questions. Many times some items in dropdownlist will become inactive (retired)or active again. It is easy to handle in the new records which use only currently active items. But how to handle the inactive items which need to be used to show history records. It bothered me a long time, not sure how to solve this problem efficiently.


Why does OwnerDrawVariable change the look of a DropDownList?

Hi, I am trying to extend a combobox to allow Enabled / Disabled items. I have everything working, except the look of the the combobox changes when Drawmode is set to OwnerDrawVariable and DropDownStyle is set to DropDownList. Why, and is there a workaround? I have tried the suggestion from this link... http://stackoverflow.com/questions/2891981/net-ownerdraw-combobox-vista-7-themed-dropdownlist/3565005#3565005 Whilst this seems to fix the appearance of the combo, it breaks most of the event code, and the OnDrawItem event, whilst fired, always has an index of -1 in the DrawItemEventArgs. I am using c#, visual studio 2010 and .net4 to create a Winforms application.   Cesare          

how to change the permissions list items using the workflow?

How to change the permissions list items using the workflow? Or how to instull SPDActivities on sharepoint 2010?

Change Item order wont work for folder items

Hello. Links lists in Sharepoint 2010 have Change Item Order Action which can order your items. I added new content type based on folder content type to my list. And When I want to order my folder items with Change Item Order action Sharepoint sorts my items randomly. For example with 4 folder items it sorts it right in 3 or 4 times. I can't see any rule in it's behavior sometimes it works sometimes not. For Link list items everything is OK. Anyone have an idea? Thanks.

Change Sqldatasource or LINQ to SQL into a DataSet? [C#]

Hi Everyone,I've saw a couple of threads on here and on different sites around this area but none I've tried have seemed to work.What I'm struggling to achieve is, I want to take a set of results attained by either a SqlDataSource or a LINQ to SQL Method and feed them into a DataSet. Why? This is because I have downloaded an example of a repeater which has paging programmed on it, but in the example it uses the DataSet.ReadXML method to read a pre-defined set of results in an XML file. As my results are constantly changing I thought it would be a good idea for the DataSet to attain them from the previous mentioned ways.I've lost count at the number of ways I've tried it, from setting up SQLConnection method seperately and the QS set as a 'string' then passing that through etc. to simply trying Dataset Items = PartialClass.GetAll(); - Which throws back Generic<List> cannot be converted to DataSet - or something close to that.I'm working from an example and incorporating it into my own project.Below is the code I'm trying to get working:C#:protected void Page_Load(object sender, EventArgs e) { // Call the ItemsGet method to populate control, // passing in the sample data. ItemsGet(); } public void ItemsGet() { // Read sample item info from XML document into a DataSet DataSe

How to Capture a DropDownList Selected Index Change Event

I have a gridview that receives data based on selection from a primary dropdownlist object. Works. Within the gridview, there is a dropdownlist whose selected index is based on the query from the primary dropdownlist. Works. Problem. How do I force the used to  change whatever value that the dropdownlist contains after they make their initial selection from the primary dropdownlist; except the default value of "Please make a selection". Gridview, contains a checkbox which drives whether a selected row is inserted into the data base. The databind in done using an ObjectDataSource on the presentation page, not in the code behind.   Thank you.   Ayomide 

Change style for aspMenu items

I am using a aspMenu that renders the horizontal global navigation with useSimpleRendering="true" so that a list (ul,li) menu implementation is used rather than the table implementation.  My question is - how do I change the style of the UL, LI elements? They have class names such as "root static", "static dynamic children", etc. etc.  I can overwrite the css definition for these styles in my custom css. But what if I want the implementation to use my css element names? I tried with using the "CssClass=classname" and "UseSeparateCss=true" for the <Sharepoint:AspMenu> .... but this doesn't seem to have any influence on the CSS elements for the List. Any suggestions? Thanks in advance, Jake.

GridView bound to SqlDataSource = 2 tier ?


Hi guys,

I've got two questions about n-tier architecture.

I have an aspx page with 2 controls on it - a GridView bound to a SqlDataSource control.
Am I correct in thinking this is 2-tier ?

If I were to replace the SqlDataSource with an ObjectDataSource, and make the database connections/calls/queries via a class in the App_Code folder, this would be 3-tier, right ?

disable a single intem in dropdownlist or stop the ddl change event for a single item


hello guys,

I am trying something apart of my boundries, is there any way to disable a single intem in dropdownlist or stop the ddl change event for a single item.

any feadback would be appriciable.

Thanks and Regards

Inderjeet Singh Khalsa

Order of the items in a DropDownList inside GridView



I have a DropDownList inside the EditTemplateItem (if the user clicks edit) in a GridView. The DropDownList receives all available rows from the database.

My problem is, if the user clicks Edit in the GridView to edit a row and opens the DropDownList Box the original item is not selected but the first one. That means the items are sorted.

Have someone an idea how I can solve this issue that the right item / the original is selected if I change to edit mode of the grid view?

The only idear that I have is to write some lines in the code behind for the updating event and selected the suitable index manually but I think there must be an easier way.


Html.DropDownList items with '<'


 How do I tell asp.net to display escape characters in a 



In the select list, there are some '>' and '<'. I used &lt; and &gt; but the page shows &lt; and &gt; instead of '<' and '>'.

Any help?


filter dropdownlist/sqldatasource


DISCLAIMER: I am very new to asp.net

I am working on a webform that allows users to access information from a database of algae species.  I have a drop down list of all algae genera for the user to chose from.  I would also like to have a check box that would allow the user to filter the drop down list so that it only shows diatom genera (diatoms are a type of algae).

Below is code that I thought should work, however checking the checkbox seems to have no effect :(

Any help would be greatly appreciated!


<script runat="server">
    Sub Page_Load()
        If chkDiatoms.Checked Then
            dsGenusList.FilterExpression = "is_diatom = 1"
            dsGenusList.FilterExpression = ""
        End If
    End Sub

<form runat="server">
<asp:CheckBox id="chkDiatoms" text="Diatoms Only" runat="server" AutoPostBack="True"/> <br>
<asp:DropDownList ID="ddlGenus" runat="server" dataSourceID="dsGenusList" dataTextField="genus"> </asp:DropDownList>
<asp:SqlDataSource ID="dsGenusList" runat=&q

Change Document Library default action on Items



I have a standard Document Library where I uploaded various  kinds of file (.pdf, swf). Whenever I click on an item (or I paste its direct link into the browser) it prompts me to download it instead of opening it into the browser directly (with flash player or acrobrat in my example).

How to obtain the desired behavior? Thanks

Programatically change a TwoWay bound control, change wasn't commited.



I had a TextBox bound to a single DataColumn with TwoWay mode,
then checked if it works by manually changing the text.

But when I programmatically changed the value of TextBox.text, the DataColumn wasn't changed.

Here is a snippet, anything wrong?

    <TextBox Name="tbName" Text="{Binding Path=DataColumn1,Mode=TwoWay}"/>
    <Button Name="Change" Click="Change_Click" Content<
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend