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 8604995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:42:54+00:00 2026-06-12T02:42:54+00:00

I have a user control that contains a repeater. The repeater contains some control,

  • 0

I have a user control that contains a repeater. The repeater contains some control, including a dropDownList with id ‘ddlPallet’. The repeater is bound to a dataset in the user controls’ Page_Load event.

I’m using the ItemDataBound event of the repeater to change the SelectedValue of the dropdownlist based on a value from the dataset.

The problem I’m having is that when the page renders, ALL of the dropdownlists’ selectedValue are set to the last selectedValue specified – i.e. If there are 8 rows in the dataset and row 8 is ‘N’ then the selected index of all instances of ‘ddlPallet’ will have a selectedValue of ‘N’

Here’s my ItemDataBound code:

Protected Sub rptCavities_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptCavities.ItemDataBound
    If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
        Dim ddl As DropDownList
        ddl = e.Item.FindControl("ddlPallet") 'get the dropdown
        ddl.Items.AddRange(Me._arrPallets) 'add items
        Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView) 'get the data row being bound
        Dim sv As String = "" 'get the value of the 'pallet' column from the dataset
        If Trim(drv("Pallet").ToString()) <> "" Then
            sv = drv("Pallet").ToString()
        Else
            sv = "N"
        End If
        ddl.SelectedValue = sv 'set the selected value of the dropdown list for this item
        'debug
        System.Diagnostics.Debug.WriteLine("----")
        System.Diagnostics.Debug.WriteLine("Control ID: " & ddl.ID)
        System.Diagnostics.Debug.WriteLine("Control Client ID: " & ddl.ClientID)
        System.Diagnostics.Debug.WriteLine(ddl.SelectedIndex.ToString() & " - " & ddl.SelectedItem.ToString() & " - " & ddl.SelectedValue)
        System.Diagnostics.Debug.WriteLine("")
    End If
End Sub

The debug output shows that the appropriate SelectValue is being set per item/per dropDownList:


Control ID: ddlPallet
Control Client ID: Cure1_rptCavities_ctl01_ddlPallet
4 – FL – FL


Control ID: ddlPallet
Control Client ID: Cure1_rptCavities_ctl02_ddlPallet
3 – EP – EP


Control ID: ddlPallet
Control Client ID: Cure1_rptCavities_ctl03_ddlPallet
0 – N – N

..etc.

This is driving me nuts. I assume I have some kind of scoping error that is causing the last-set index value to apply to all instances of the dropDownList in the repeater, but I’m having no luck figuring out where or why. If I bind the same data to a label in the ASCX file using “Text='<%#Container.DataItem(“Pallet”)%>'” the correct data is displayed.

  • 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-06-12T02:42:55+00:00Added an answer on June 12, 2026 at 2:42 am

    It may be because you’re adding the same items to the drop down list in every case, rather than binding the dropdownlist to the source data. This way, they all share a common set of items, and if you set Selected = true to one item, it’ll be true for every dropdownlist that contains that item.

    Potentially an interesting technique, but probably not what you want.

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

Sidebar

Related Questions

I have a user control that contains a collection of controls to be reused
I have a user control that contains multiple controls (CheckBox, Button, Label...). I want
I have a simple user control that contains some buttons that fire events which
I have an ASP.Net user control that contains some checkboxes, and I want to
I have the following code in a custom user control that contains a DropDownList
I have a user control that has button whose click event handler contains the
I have a user control that contains a repeater. I populate the datasource for
I have a user control that contains a repeater. I use the Eval() method
I have a user control that contains a repeater. It seems that data cannot
I have a web user control that contains several other (web user) controls and

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.