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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:48:10+00:00 2026-06-17T22:48:10+00:00

I am using a gridview which is having dropdownlist in edittemplate field. There are

  • 0

I am using a gridview which is having dropdownlist in edittemplate field. There are 3 list items in dropdown : Red,Amber,Green. Instead of displaying text in listitems, I want to show the colors, for the same I am using dropdownlist’s onLoad event, however this event is not able to recognize the dropdownlist.
Dropdownlist Designer code :

<asp:TemplateField HeaderText="Color">
<EditItemTemplate> 
  <asp:DropDownList ID="ddlcolor" runat="server" AppendDataBoundItems="true" DataTextField="COLOR" DataValueField ="COLOR" OnLoad="DDLColor_Load">
            <asp:ListItem Value="-1">- Select Color -</asp:ListItem>
            <asp:ListItem Value="0">Amber</asp:ListItem>
            <asp:ListItem Value="1">Green</asp:ListItem>
            <asp:ListItem Value="2">Red</asp:ListItem>                
  </asp:DropDownList></EditItemTemplate></asp:TemplateField>

Dropdownlist onLoad Event in codebehing :

  protected void DDLColor_Load(object sender, EventArgs e)
{

    for (int i = 0; i < ddlcolor.Items.Count; i++)
    {
        ddlcolr.Items[i].Attributes.Add("style", "background-color:" + ddlcolor.Items[i].Text);

    }
} 

However, it shows that the dropdownlist ddlcolor does not exists in current context.
Do I need to find this control in gridview ? Please suggest.

  • 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-17T22:48:11+00:00Added an answer on June 17, 2026 at 10:48 pm

    You are right. You need to find the control. Using the sender argument will help you locate the drop down without using the find control method

     protected void DDLColor_Load(object sender, EventArgs e)
     {
        DropdownList ddlcolr=(Dropdownlist)sender;
    for (int i = 0; i < ddlcolor.Items.Count; i++)
      {
        ddlcolr.Items[i].Attributes.Add("style", "background-color:" + ddlcolor.Items[i].Text);
    
      }
     } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using vb.net code in which I am having a gridview control. Please
I have a GridView which allows users to enter data using a EmptyDataTemplate. There
I am using a GridView control which is databound to a List of objects
I have a ListView which is using a GridView to display a DataTable and
We're using a WPF GridView that is dynamically bound to a DataTable (which in
I am using a website which contains a gridview for view details of Product
I have an ASP.NET(2.0 using C#) web app, in which I have a gridview.
I am using GridView for displaying groups of different sets of items in a
So, I'm trying to have a field in a gridview which is a link
I am using the standard gridview source for my app. The problem which i

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.