0

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"));
}

3 Answers 3

3

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);
            }
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

column header are added from the dataset as well.
Set Gridview data source , use jQuery i fixed it: ` <script type="text/javascript"> $(function () { $("#<%=GridView1.ClientID %>").find("tbody tr th a").each(function (index) { $(this).attr("title", $(this).html()); }); }); </script>` , and added your project jQuery Tooltip plugin, this code paste : $("#<%=GridView1.ClientID %>").find("tbody tr th a").tooltip();
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.