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

Related Questions

Good Evening All, I have a textbox that needs to accept 14 digits plus
Evening all, Actually, it's night. About 11pm. My brain is shutting down and I
Evening All, Had a question on whether or not the use of Absolute postioning
Good evening I've got a little problem with my DataGridView in a .NET Windows
I posted this question yesterday evening, which has led me to discover a huge
I've been mucking around with GlassFish v3 prelude this evening. A couple of things
Good morning, afternoon, evening or night (depending on your timezone). This is just a
inside a jquery method (on a click event of a button) i have the
I spent the rest of the evening reading StackOverflow questions and also some blog
I must be missing something stupid here but I can not see it. My

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.