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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:58:59+00:00 2026-05-13T12:58:59+00:00

I have the following code that I think should work – however, what I

  • 0

I have the following code that I think should work – however, what I think and what actually works is something completely different! This being demonstrated by the fact it doesn’t work!

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        Dictionary<String, String> headerTooltips = new Dictionary<String, String>();
        headerTooltips["UnitId"] = "text goes here";
        headerTooltips["Product Description"] = "text goes here";
        headerTooltips["Productpriority"] = "text goes here";
        headerTooltips["Buyer"] = "text goes here";
        headerTooltips["Sub-Category"] = "text goes here";
        headerTooltips["Material"] = "text goes here";
        headerTooltips["Packaging Type"] = "text goes here";
        headerTooltips["Weight (g)"] = "text goes here";
        headerTooltips["Status"] = "text goes here";
        headerTooltips["Source"] = "text goes here";
        headerTooltips["Weighed Date"] = "text goes here";
        headerTooltips["Product %"] = "text goes here";
        headerTooltips["Recycled Content %"] = "text goes here";
        headerTooltips["Biodegradable"] = "text goes here";
        headerTooltips["Recyclability Notes"] = "text goes here";
        headerTooltips["Feedback"] = "text goes here";

       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"))
                    {
                        String headerText = cell.Text;
                        cell.Attributes.Add("title", headerTooltips[headerText]);
                    }

                }
            }
        }
    } 

So essentially I would like a tooltip to be assigned to each column I have in my gridview i.e. hover over Unit to reveal “text goes here”

However, when I know attempt to populate the gridview, I receive a “KeyNotFoundException” – “The given key was not present in the dictionary” error.

Could someone point out where I am going wrong with this?

Gridview code:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" 
        DataSourceID="LQProductWeightsDS" CellPadding="4" Font-Size="X-Small" 
        ForeColor="#333333" GridLines="None" 
        style="z-index: 1; left: 25px; top: 550px; position: absolute; height: 150px;  width: 1400px; text-align: center;" 
            DataKeyNames="PriKey" 
            >
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <Columns>
         <asp:BoundField DataField="Productpriority" HeaderText="Productpriority" 
                    SortExpression="Productpriority" ReadOnly="True" Visible="False" />
                <asp:BoundField DataField="UnitId" HeaderText="Product ID" 
                    SortExpression="UnitId" ReadOnly="True" >
                <HeaderStyle Width="100px" />
                </asp:BoundField>
                <asp:BoundField DataField="UnitDescription" HeaderText="Product Description" 
                    SortExpression="UnitDescription" ReadOnly="True">
                <HeaderStyle Width="450px" />
                </asp:BoundField>
                <asp:BoundField DataField="UnitUserfield1" HeaderText="Buyer" 
                    SortExpression="UnitUserfield1" ReadOnly="True" >
                <HeaderStyle Width="450px" />
                </asp:BoundField>
                <asp:BoundField DataField="UnitUserfield2" HeaderText="Sub-Category" 
                    SortExpression="UnitUserfield2" ReadOnly="True" >
                <HeaderStyle Width="450px" />
                </asp:BoundField>
               <asp:BoundField DataField="MaterialText" HeaderText="Material" 
                    SortExpression="MaterialText" ReadOnly="True" />
                <asp:BoundField DataField="PackagingTypeCode" HeaderText="Packaging Type" 
                    SortExpression="PackagingTypeCode" ReadOnly="True" >
                <HeaderStyle Width="250px" />
                </asp:BoundField>
                <asp:BoundField DataField="UnitWeight" HeaderText="Weight (g)" 
                    SortExpression="UnitWeight" DataFormatString="{0:F2}" ReadOnly="True" 
                    ShowHeader="False" >
                <HeaderStyle Width="200px" />
                </asp:BoundField>
                <asp:BoundField DataField="WeightStatus" HeaderText="Status" 
                    SortExpression="WeightStatus" ReadOnly="True" />
                <asp:BoundField DataField="RevisionSourceCode" HeaderText="Source" 
                    SortExpression="RevisionSourceCode" ReadOnly="True" />
                <asp:BoundField DataField="RevisionDate" HeaderText="Weighed Date" 
                    SortExpression="RevisionDate" DataFormatString="{0:dd/MM/yyyy}" 
                    ReadOnly="True" >    
                <HeaderStyle Width="200px" />
                </asp:BoundField>
                <asp:BoundField DataField="ProductPercentage" HeaderText="Product %" 
                    SortExpression="ProductPercentage" DataFormatString="{0:F4}" 
                    ReadOnly="True" >
                <HeaderStyle Width="100px" />
                </asp:BoundField>
                <asp:BoundField DataField="RecycledContent" HeaderText="Recycled Content %" 
                    SortExpression="RecycledContent" ReadOnly="True" >
                <HeaderStyle Width="350px" />
                </asp:BoundField>
                <asp:BoundField DataField="IsBiodegradable" HeaderText="Biodegradable" 
                    SortExpression="IsBiodegradable" ReadOnly="True" />
                <asp:BoundField DataField="Recyclability" HeaderText="Recyclability Notes" 
                    SortExpression="Recyclability" ReadOnly="True" >
                <HeaderStyle Width="250px" />
                </asp:BoundField>
                <asp:BoundField DataField="Feedback" HeaderText="Feedback" 
                    SortExpression="Feedback" >
                    <HeaderStyle Width="750px" />
                </asp:BoundField>

            <asp:CommandField ShowEditButton="True" />


        </Columns>
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#999999" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>
  • 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-13T12:58:59+00:00Added an answer on May 13, 2026 at 12:58 pm

    Without seeing the design-view Gridview code, I was able to get the code to work by making the following changes:

        if (e.Row.RowType == DataControlRowType.Header)
        {
            foreach (TableCell cell in e.Row.Cells)
            {
                String headerText = cell.Text;
                cell.Attributes.Add("title", headerTooltips[cell.Text]);
            }
        }
    

    If you can post the design-view code, I might be able be able to figure out what’s going on. Here’s what I used in my set up:

           <asp:GridView ID="GridView1" runat="server" onrowdatabound="GridView1_RowDataBound" AutoGenerateColumns="false" AllowSorting="true">
            <Columns>
                <asp:BoundField DataField="UnitId" HeaderText="UnitId" />
                <asp:BoundField DataField="ProductDesc" HeaderText="Product Description" />
            </Columns>
        </asp:GridView>
    

    Obviously I didn’t add the full dataset.

    Update 2: Give this a try:

        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"))
                    {
                        String headerText = ((LinkButton)ctl).Text;
                        cell.Attributes.Add("title", headerTooltips[headerText]);
                    }
    
                }
            }
        }
    

    In think the problem was you were trying to read the text of the cell instead of the text of the control.

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

Sidebar

Related Questions

Work on this small test application to learn threading/locking. I have the following code,
I have the following code that shows either a bug or a misunderstanding on
I am pretty new to jQuery in general, however the following code works perfectly
I have the following code in a custom module as well as I have
I have a problem with the following code: protected void onDraw(Canvas canvas) { Paint
I've got the following code, think simple shooter in c++: // world.hpp //---------- class
I have 2 select boxes on a page with a variable number of options
I have created a C# Windows Forms application which I've attempted to make as
Working with Sitecore and Linq extensions. I am trying to convert to from an

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.