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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:53:23+00:00 2026-05-13T05:53:23+00:00

Evening all. I have the following code that I need looking into – basically

  • 0

Evening all.

I have the following code that I need looking into – basically I’m clutching at straws here. I have a gridview that I would like to assign tooltips to.

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            foreach (TableCell cell in e.Row.Cells)
            {
                foreach (System.Web.UI.Control ctl in cell.Controls)
                {
                    if (ctl.GetType().ToString().Contains("DataControlLinkButton"))
                    {
                        Dictionary<String, String> headerTooltips = new Dictionary<String, String>();
                        headerTooltips["Product ID"] = "A unique product ID";
                        headerTooltips["Product Description"] = "Description of product";

                        String headerText = cell.Text; 
                        cell.Attributes.Add("title", headerTooltips[headerText]);

                    }
                }
            }
        }

    }

Essentially what I am trying to achieve is a tool tip that appears by each column heading (i.e. Product ID and Product Description.)

However, when I use the above code, I receive the following error message “The given key was not present in the dictionary.” This appears on the

cell.Attributes.Add("title", headerTooltips[headerText]);

line.

Can someone point out the error in my ways? Thank you for any help or suggestions.

  • 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-13T05:53:24+00:00Added an answer on May 13, 2026 at 5:53 am

    The error is caused because you haven’t added an entry to your dictionary that corresponds to the value of cell.Text. The only keys your dictionary contains is ‘Product ID’ and ‘Product Description’ so unless you have cells that actually contain this text it will always fail. You could do this:

    if (headerTooltips.ContainsKey(headerText))
    {
        cell.Attributes.Add("title", headerTooltips[headerText]);
    }
    

    Which gets you beyond the exception but don’t think it does what you are trying to accomplish.

    Edit:

    Do you just want the cell.Text to show up as the tooltip? If yes then do this:

    // This is only replacing the foreach part, the rest of your code is still valid
    foreach (System.Web.UI.Control ctl in cell.Controls)
    {
        if (ctl.GetType().ToString().Contains("DataControlLinkButton"))
        {
            cell.Attributes.Add("title", cell.Text);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 265k
  • Answers 265k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here we go: /(\d{3})\D*(\d{3})\D*(\d{4})\D*(\d*)/ Area Code, Prefix, Suffix, Extension in… May 13, 2026 at 12:23 pm
  • Editorial Team
    Editorial Team added an answer As an addition to the @Daniel's answer, if you want… May 13, 2026 at 12:23 pm
  • Editorial Team
    Editorial Team added an answer Here's an explanation: ^ # match the beginning of the… May 13, 2026 at 12:23 pm

Related Questions

I posted this question yesterday evening, which has led me to discover a huge
Before starting, note that I have to update a website that is not mine,
Good evening/morning/after/noon. I have an ASP.net 3.5 website and I am using vb.net in
Good evening/morning/after/noon. I have an ASP.net 3.5 website and I am using vb.net in
How can I get all items from a specific calendar (for a specific date).

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.