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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:09:49+00:00 2026-05-31T12:09:49+00:00

I have a DropDownList inside a repeater control in an ASP.NET page that has

  • 0

I have a DropDownList inside a repeater control in an ASP.NET page that has predefined items. How would I go about setting the selected value of it after binding the data to the repeater control?

For example, I have this code:

<asp:DropDownList ID="cboType" runat="server">
    <asp:ListItem Text="Communication" Value="Communcation" />
    <asp:ListItem Text="Interpersonal" Value="Interpersonal" />
</asp:DropDownList>

Because the DropDownList control doesn’t have a SelectedValue front-end property, I can’t set it on the control level. Instead you have to use the selected property of the list item. What would be ideal is:

<asp:DropDownList ID="cboType" runat="server" SelectedValue='<%# Eval("Type_Of_Behavior") %>'>
    <asp:ListItem Text="Communication" Value="Communcation" />
    <asp:ListItem Text="Interpersonal" Value="Interpersonal" />
</asp:DropDownList>

Unfortunately that won’t work, any ideas?

  • 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-31T12:09:51+00:00Added an answer on May 31, 2026 at 12:09 pm

    Using the code from Pankaj Garg (thank you!) I’ve managed to write up the method to select the correct value. I couldn’t mark it as the answer as that answer is selecting a static value, but not one that is coming from the DB. Here’s the function:

    protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DropDownList cbo = (DropDownList)e.Item.FindControl("cboType");
            Behaviour b = (Behaviour)e.Item.DataItem;
    
            for (int i = 0; i < cbo.Items.Count; i++)
            {
                if (b.Type_of_Behaviour == cbo.Items[i].Value)
                    cbo.Items[i].Selected = true;
                else
                    cbo.Items[i].Selected = false;
            }
        }
    }
    

    Thanks to everybody who helped out.

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

Sidebar

Related Questions

Greetings, I have asp.net check box control and asp.net dropdownlist control inside div tag.
I'm building an asp.net cutom control inside which I have two dropdownlists: companyIdSelection and
I have a dropdownlist inside a gridview, that is loaded from a datasource when
I have a web user control with a dropdownlist inside of it. When the
I have a dropdownlist in a page. The values of all the list items
I have DropDownList inside GridView. Now I would like to add event handler for
I have an application with star rating. Star rating inside repeater. <asp:Repeater ID=reptweet runat=server
I have a Razor view in my asp.net MVC3 application with a dropdownlist like
I have a asp.net component inside a ColorBox window, and after choosing a country
I have following code inside my ListView template. <asp:DropDownList runat=server ID=myDropDown Width=60px SelectedValue='<%# Eval(SelectedValue)

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.