Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 663259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:28:12+00:00 2026-05-13T23:28:12+00:00

I have a UserControl, containing a FormView, containing a DropDownList. The FormView is bound

  • 0

I have a UserControl, containing a FormView, containing a DropDownList.
The FormView is bound to a data control.

Like so:

<asp:FormView ID="frmEdit" DataKeyNames="MetricCode" runat="server" DefaultMode="Edit" DataSourceID="llbDataSource" Cellpadding="0" >
    <EditItemTemplate>
        <asp:DropDownList ID="ParentMetricCode"  runat="server" SelectedValue='<%# Bind("ParentMetricCode") %>' />
    </EditItemTemplate>
<asp:FormView>

I am trying to populate the DropDownList from the codebehind. If this was not contained in a FormView, I would normally just do it in the Page_Load event. However, that does not work within a FormView, as as soon as I try to do it, accessing the dropdownlist in code, i.e.:

theListcontrol = CType(formView.FindControl(listControlName), ListControl)  

…the data binding mechanism of the FormView is invoked, which, of course, tries to bind the DropDownList to the underlying datasource, causing a **’ParentMetricCode’ has a SelectedValue which is invalid because it does not exist in the list of items. “Parameter name: value …” error, since the DropDownList has not yet been populated.

I tried performing the load in the DataBinding() event of the FormView, but then:

theListcontrol = CType(formView.FindControl(listControlName), System.Web.UI.WebControls.ListControl)

…fails, as the FormView.Controls.Count = 0 at that point.

Is this impossible? (I do not want to have to use a secondary ObjectDataSource to bind the dropdownlist to)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:28:12+00:00Added an answer on May 13, 2026 at 11:28 pm

    Ok, found “a” solution:
    1. Call the DDL populate function from the FormView_ItemCreated event.
    2. Modify the code to populate the DDL like so:

    Public Overloads Shared Sub BindListControl(Of theLLBLgenEntityType As EntityBase) _   
            (ByVal formView As FormView, _
            ByVal listControlName As String, _
            ByVal theCollection As CollectionCore(Of theLLBLgenEntityType), _
            ByVal DataValueField As EntityField, _
            ByVal DataTextField As EntityField, _
            ByVal IncludeEmptyItem As Boolean)
    
        If formView.CurrentMode = FormViewMode.Edit Then
            Dim theListcontrol As System.Web.UI.WebControls.ListControl
            theListcontrol = CType(formView.FindControl(listControlName), System.Web.UI.WebControls.ListControl)
    
        For Each entity As theLLBLgenEntityType In theCollection
            theListcontrol.Items.Add(New ListItem(entity.Fields(DataTextField.Name).CurrentValue.ToString, entity.Fields(DataValueField.Name).CurrentValue.ToString))
        Next
    
        If IncludeEmptyItem Then 
            theListcontrol.Items.Insert(0, New ListItem("", ""))
        End If
    End Sub
    

    It kinda seems to basically boil down to, you cannot do additional “Databinding”, programatically at runtime, within a FormView.

    (Anyone know why the formatting of my code is all screwed up in this post??)

    Update

    This solution raises yet another batch of issues, related to inserting new items. After a lot of screwing around I eventually found a way around that. At this point, I am basically at the point where I would recommend either avoiding the FormView control entirely, or definitely avoid programatically altering bound controls. Hopefully, perhaps using seperate data controls for each DropDownList might work better, but this might be wishful thinking as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have UserControl which contains a TextBox and a Button control. The Button opens
I have a UserControl in my Asp.net project that has a public property. I
So I have a UserControl with some cascading DropDownList s on it. Selecting from
I have a usercontrol that has several public properties. These properties automatically show up
I have a UserControl that consists of three TextBoxes. On a form I can
I have a UserControl with some predefined controls (groupbox,button,datagridview) on it, these controls are
I have a usercontrol that is meant to take up the entire form. I
I have a UserControl called CustomerFinder for searhing customers. And there is "ADD" button
If I have a usercontrol (in Silverlight) that I've written, that uses XAML to
I have created a UserControl that has a ListView in it. The ListView is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.