+ Reply to Thread
Results 1 to 2 of 2

Thread: SelectedValue from dependant dropdownlist

  1. #1
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    SelectedValue from dependant dropdownlist

    I have 2 dropdownlist controls on my web form page. The page content sits inside an update panel on my master page.

    When one dropdown is changed, the items in the other dropdown are populated based on the selection made. This is done via a web service call.

    When I then call a button click event, no value is returned by my dependent dropdown control.
    Code:
                       <li style="clear: both;">
                                <asp:Label ID="lblCategory" runat="server" Text="Product Category" />
                                <span class="red bold size_12" style="text-align: left; width: 5px; cursor: help;"
                                    title="Required">*</span>
                                <asp:DropDownList ID="ddlCategory" runat="server" CssClass="blue_333399 size_9 textbox"
                                    DataValueField="id" DataTextField="category" />
                                <asp:RequiredFieldValidator ID="rfvCategory" runat="server" ControlToValidate="ddlCategory"
                                    ErrorMessage="Please select the category" Display="None" EnableClientScript="true"
                                    ValidationGroup="evalproduct" />
                            </li>
                            <li style="clear: both;">
                                <asp:Label ID="lblReceptor" runat="server" Text="Product Receptor" />
                                <span class="red bold size_12" style="text-align: left; width: 5px; cursor: help;"
                                    title="Required">*</span>
                                <asp:DropDownList ID="ddlReceptor" runat="server" CssClass="blue_333399 size_9 textbox" style="display:none;" />
                                <div id="pHReceptor" class="blue_333399 size_9" style="line-height:23px;">Please select a product category</div>
                            </li>
    
    I have also overridden the Render event to prevent Event Validation problems.
    Code:
        protected override void Render(HtmlTextWriter writer)
        {
            this.ddlReceptor.DataSource = Receptor.GetAllReceptorList();
            this.ddlReceptor.DataValueField = "id";
            this.ddlReceptor.DataTextField = "receptor";
            this.ddlReceptor.DataBind();
            this.ddlReceptor.Items.Add(new ListItem("None", "0"));
            base.Render(writer);
        }
    
    In my button click event though, ddlReceptor.SelectedValue is coming back blank.

    Any ideas?

  2. #2
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    OK. I just scrapped the web service population even though the rendering is slightly better and just went for the OnSelectedIndexChanged on the ddlCategory control.

    btw, the rendering is better because I also have FCKEditor controls on my page. Using OnSelectedIndexChanged causes a postback that refereshes the FCKeditors. Using the web service stops this, but I guess I'll just have to live with it...

+ Reply to Thread

Similar Threads

  1. Special Characters in DropDownList
    By richyrich in forum HTML & CSS Help
    Replies: 3
    Last Post: January 5th, 2010, 08:19 AM
  2. Dynamically Populate DropDownList with Range of Years
    By todd2006 in forum .NET Development
    Replies: 25
    Last Post: March 20th, 2009, 07:24 PM
  3. How do you add a static item to a dynamic dropdownlist
    By Shem in forum .NET Development
    Replies: 19
    Last Post: July 4th, 2008, 09:14 AM
  4. Programmatically Select Item in ListBox or DropDownList
    By jmurrayhead in forum .NET Code Samples
    Replies: 0
    Last Post: June 27th, 2008, 11:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO