user1292656
user1292656

Reputation: 2560

Gridview Column Add tooltip to column

I'm working on an ASP.NET project and I'm trying to add a ToolTip on GridView columns header that are added from a DataSet. Any help please? This is the code that I'm using to bind the columns.

for (int i = 0; i < answers; i++)
{
    ds.Tables[0].Columns.Add(dans.Tables[0].Rows[i]["level"].ToString(), Type.GetType("System.Boolean"));
}

Upvotes: 0

Views: 6480

Answers (3)

shary.sharath
shary.sharath

Reputation: 709

This can be done using JavaScript also, add a CSS class to the column where you want to put the tooltip. Then in JavaScript add the title attribute.
Following is the example:

<asp:GridView ID="GridView1" runat="server">
  <Columns>
    <asp:BoundField DataField="DIAGNOSIS_CODE" HeaderText="Diagnosis Code"/>
    <asp:ButtonField DataTextField="DIAGNOSIS_NAME" HeaderText="Diagnosis Name"
         ControlStyle-CssClass="DiagButton" />
    <asp:BoundField DataField="ICD_CODE" HeaderText="ICD Code"/>
    <asp:BoundField DataField="ICD_NAME" HeaderText="ICD Name" />
  </Columns>
</asp:GridView>

JavaScript

$(document).ready(function () {
        $(".DiagButton").attr("title", "Click to Edit Diagnosis Name");
    });

This will add the title Attribute to the column which has the class .DiagButton

Upvotes: 0

Ronak
Ronak

Reputation: 61

You can use this code for the give a tooltip to a particular column

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Utility.RowColorChange(e);
            for (int colIndex = 0; colIndex < e.Row.Cells.Count; colIndex++)
            {
                string ToolTipString = "Edit Records";
                e.Row.Cells[5].Attributes.Add("title", ToolTipString);
            }
        }
    }

Upvotes: 3

Elyor
Elyor

Reputation: 865

OK!,i your issue fixed for 2-option fixing:

1)By Design -> Set Gridview->Add Columns->Edit Column Property -> enter image description here

2)By source click here this link ,from MSDN.

Upvotes: 0

Related Questions