Wrox Programmer Forums
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 1st, 2011, 01:08 PM
Registered User
 
Join Date: Oct 2011
Posts: 18
Thanks: 0
Thanked 2 Times in 2 Posts
Question Items Doubled in DropDownList

I've encountered a problem that seems to have me stuck. I have a DropDownList3 that gets filtered by the values of two other dropdownlists ( 1 and 2) on the form. DropDownlist3 should show:

--- Select Item ---
AAAAAAAAAAAAAA
BBBBBBBBBBBBBBBB

But instead it shows:

--- Select Item ---
AAAAAAAAAAAAAA
BBBBBBBBBBBBBBBB
AAAAAAAAAAAAAA
BBBBBBBBBBBBBBBB

It seems perfectly functional otherwise. Now if I take away the AppendDataBoundItems="True", then it shows only two items, but it does not show the --- Select Item --- at the top, which prevents the AAAAAAAAAA SelectedIndexChanged event from firing when you click the top item. The same is true if I remove the "<asp:ListItem Value="">--- Select Item ---</asp:ListItem>".

Here is the code:


Code:
 <asp:Label id="ItemId" AssociatedControlId="DropDownList3" Text="Item: " runat="server" />
        <asp:DropDownList ID="DropDownList3" runat="server" 
    DataSourceID="SqlDataSource3" DataTextField="ITEM_DESCR" 
    DataValueField="ID_KEY" AutoPostBack="True" 
    onselectedindexchanged="DropDownList3_SelectedIndexChanged" 
          AppendDataBoundItems="True" CssClass="RightMargin">
    <asp:ListItem Value="">--- Select Item ---</asp:ListItem>
  </asp:DropDownList>



<asp:SqlDataSource ID="SqlDataSource3" runat="server" 
    ConnectionString="<%$ ConnectionStrings:BCConnectionString %>" 
             
    SelectCommand="SELECT [ITEM_DESCR], [ITEM_ID], [HEADING], [SUB_HEADING], [ID_KEY] FROM [QPURCH] WHERE (([EMP_NAME] = 

@userName) AND ([FORM_NAME] = @FORM_NAME) AND ([DEPT] = @DEPT)) ORDER BY [HEADING], [SUB_HEADING], [ITEM_DESCR]" 
    onselecting="SqlDataSource3_Selecting"> 
          
    <SelectParameters>
      <asp:Parameter Name="UserName" Type="String" />
      <asp:ControlParameter ControlID="DropDownList2" Name="FORM_NAME" 
        PropertyName="SelectedValue" Type="String" />
      <asp:ControlParameter ControlID="DropDownList1" Name="DEPT" 
        PropertyName="SelectedValue" Type="String" />
    </SelectParameters>

  </asp:SqlDataSource>

Last edited by BobRoberts; November 1st, 2011 at 01:18 PM..
 
Old November 1st, 2011, 01:48 PM
Registered User
 
Join Date: Oct 2011
Posts: 18
Thanks: 0
Thanked 2 Times in 2 Posts
Smile Solution

After searching for awhile and trying several things out, I think I found the solution: I removed the AppendDataBoundItems="True" from the control, and put the following in the DropDownList3 DataBound event code-behind:

Code:
    if (DropDownList3.Items.Count > 0)
    {
      DropDownList3.Items.Insert(0, "--- Select Item ---");
      DropDownList3.Items[0].Value = "";
      DropDownList3.SelectedIndex = 0;

    }





Similar Threads
Thread Thread Starter Forum Replies Last Post
PROGRAMMING APPEARANCE OF DROPDOWNLIST HOVER ITEMS bankole BOOK: Beginning ASP.NET 4 : in C# and VB 1 February 11th, 2011 05:07 AM
Dropdownlist Items Identification msbsam ASP.NET 2.0 Professional 1 August 18th, 2008 12:50 PM
DropDownList, DataSource and Selected Items kingroon ASP.NET 2.0 Basics 2 February 25th, 2008 10:41 AM
Finding items in a dropdownlist control johnnycorpse Classic ASP Components 0 May 18th, 2007 04:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.