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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:19:42+00:00 2026-06-17T20:19:42+00:00

how do you properly call methods inside custom binding expressions? Are there complications because

  • 0

how do you properly call methods inside custom binding expressions? Are there complications because the dropdownlist is inside a detailsview?

asp.net code:

<asp:DropDownList ID="ddlExceptionEditStatus" runat="server"
      DataSourceID="odsExceptionsStatus"
      DataTextField="Name"
      DataValueField="StatusID"
      SelectedValue='<%# Bind("StatusID") %>' 
      BackColor="<%# SetBackColorProp(Container.DataItem) %>">
 </asp:DropDownList>

code behind:

protected System.Drawing.Color SetBackColorProp(object o)
{
    System.Drawing.Color statusColor = System.Drawing.Color.White;
    string statusName = o as string;
    if (statusName != null)
    {
        statusColor = System.Drawing.ColorTranslator.FromHtml(FISBLL.StatusColors.GetColor(statusName));
        return statusColor;
    }
    else
    {
        return statusColor;
    }        
}

Doesn’t change the backcolor. but doesn’t throw an exception.

  • 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-17T20:19:42+00:00Added an answer on June 17, 2026 at 8:19 pm

    So, I had two mistakes:

    1) I needed to cast the Container.DataItem to the class object i was using for the ObjectDataSource. After casting, the BackColor for each item in the dropdownlist matched the StatusID of the casted Container.DataItem.

    2) Unfortunately this gave all the items the same color, where as I wanted each item’s color to reflect the their own value attached to the dropdownlist. This is because the dropdownlist has an objectdatasource outside the DetailsView that it’s inside of. Therefor the selectedValue item of the dropdownlist dictated the colors for all the other items.

    I decided to go with Tim’s suggestion and tie the BackColor setting for each item in the databound event:

    protected string GetColor(string name)
    {
        return FISBLL.StatusColors.GetColor(name);
    }
    
    protected void ddlExceptionEditStatus_DataBound(object sender, EventArgs e)
    {
        foreach (ListItem item in ((DropDownList)sender).Items)
        {
            item.Attributes.Add("style", "background-color:" + GetColor(item.Text));
        }
    
    }
    

    And the correct behavior is shown:

    enter image description here

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

Sidebar

Related Questions

Users call a web service API in my PHP code but don't properly encode
How can I tell if my call to SendInput is working properly? I have
This code doesn't work propely: I call a function passing a variable What's the
I do know there are already many questions on Stackoverflow related to custom error
I am trying to create bunch of void methods and call them later in
I have a couple of questions about the way I call methods in EL.
I have a ThreadPoolExecutor I've created with a custom ThreadFactory . When I call
After reading on the benefits (and using) the Repository Design pattern within an ASP.NET
There is basic persistence of Javascript vars/etc. You call a function/method, and the next
I have a UITableView with custom cells. Inside each cell is 2 views. Each

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.