Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 1st, 2011, 01:08 PM
Registered User
Points: 87, Level: 1
Points: 87, Level: 1 Points: 87, Level: 1 Points: 87, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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..
Reply With Quote
  #2 (permalink)  
Old November 1st, 2011, 01:48 PM
Registered User
Points: 87, Level: 1
Points: 87, Level: 1 Points: 87, Level: 1 Points: 87, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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;

    }
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:17 PM.


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