ASP.NET - Add tooltip to gridview in asp.net

Asked By rajeev chandra on 01-Nov-11 12:10 AM
How to Add Tolltip to Gridview in asp.net on mouse hover for the cells in gridview

Jitendra Faye replied to rajeev chandra on 01-Nov-11 12:17 AM
For this implement GridView RowDataBound event like this-


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{


if (e.Row.RowType == DataControlRowType.DataRow)

{


CheckBox cb;

Label lb;

cb = (CheckBox)e.Row.FindControl("cb_active");

lb = (Label)e.Row.FindControl("lbl_msg");

cb.Attributes.Add("onmouseover", cb.ToolTip = "Check to add");

lb.Attributes.Add("onmouseover", "alert('Show your Message here')");

}

}



Try this code and let me now.
aneesa replied to rajeev chandra on 01-Nov-11 12:27 AM
You can use the rowdatabound event to add an attribute "title" (which is tooltip) to each cell of each row. But before adding this attribute, lookup in database for whatever information you want associated with that cell. Put it in a string variable and supply that variable as the value of "title"
 
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
   for (int colIndex = 0; colIndex < e.Row.Cells.Count; colIndex++)
   {
     // Do database lookup
     // string ttString = "Result of database lookup";
     e.Row.Cells[colIndex].Attributes.Add("title", ttString);
   }
}
Riley K replied to rajeev chandra on 01-Nov-11 12:51 AM



Simply Set the ToolTip Property

<asp:TemplateField>
        <ItemTemplate>
          <asp:Label ID="Label1" runat="server"
             ToolTip='<%# Eval("ItemDescription") %>'
             Text='<%# Eval("ItemID") %>'>
          </asp:Label>
        </ItemTemplate>


Regards
rajeev chandra replied to Jitendra Faye on 01-Nov-11 01:06 AM
thanks 
Jitendra Faye replied to rajeev chandra on 01-Nov-11 01:09 AM
You always welcome.
Kirtan Patel replied to rajeev chandra on 01-Nov-11 01:17 AM
Here is how you can do that

Untitled document
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
   for (int colIndex = 0; colIndex < e.Row.Cells.Count; colIndex++)
   {
     e.Row.Cells[colIndex].Attributes.Add("title", ttString);
   }
}
 
Reena Jain replied to rajeev chandra on 01-Nov-11 01:27 AM
HI,

Use RowDataBind event to get access to the cell and add content to the tooltip property

or try this

private void Dgv_CellMouseMove(Object sender, DataGridViewCellMouseEventArgs e)
{
if (e.RowIndex != -1 && e.ColumnIndex == 2)
{
DataGridViewCell cell = this.Dgv.Rows[e.RowIndex].Cells[2];
cell.ToolTipText = Dgv[2, e.RowIndex].Value.ToString();
}
}
DL M replied to rajeev chandra on 01-Nov-11 01:57 AM
Tool tip text in an ASP.NET GridView on MouseOver, to display these we needs to handle the RowDataBound event of GridView.

The RowDataBound event is raised when a data row (represented by a GridViewRow object) is bound to data in the GridView control. This enables you to provide an event-handling method that performs a custom routine, such as modifying the values of the data bound to the row, whenever this event occurs.

Ex:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound">
    <Columns>
      <asp:TemplateField>
        <HeaderTemplate>
          <asp:CheckBox ID="cb_chkall" runat="server" />
        </HeaderTemplate>
        <ItemTemplate>
         <asp:CheckBox ID="cb_active" runat="server" />
        </ItemTemplate>
     </asp:TemplateField>
     <asp:TemplateField>
       <ItemTemplate>
          <asp:Label ID="lbl_msg" runat="server" text="Msg"></asp:Label>
        </ItemTemplate>
      </asp:TemplateField>
     <asp:TemplateField>
       <ItemTemplate>
          <asp:Label ID="lbl_Name" runat="server" text='<%#Eval("Name")%>'>           </asp:Label>
        </ItemTemplate>
      </asp:TemplateField>
    </Columns>
</asp:GridView>

Row Data Bound Event

Displaying tootip text or Alert message when you placed mouse on Particular columns

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
 {
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
     CheckBox cb;
     Label lb;
     cb = (CheckBox)e.Row.FindControl("cb_active");
     lb = (Label)e.Row.FindControl("lbl_msg");

     cb.Attributes.Add("onmouseover", cb.ToolTip = "Check to add");
     lb.Attributes.Add("onmouseover", "alert('Show your Message here')");
         
    }
}


Displaying Alert Message when you placed mouse on Particular Row



protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if ( e.Row.RowType == DataControlRowType.DataRow )
   {
      e.Row.Attributes.Add("onmouseover", "alert('Display some message');");
   }
}

Devil Scorpio replied to rajeev chandra on 01-Nov-11 01:46 PM
Hi,

You should be able to add the tooltip to each cell / column like so:

gridview.rows(x).cells(y).ToolTip="blah"

or say in the RowDataBound event...

e.Row.Cells(x).ToolTip="blah"