Overblog Follow this blog
Edit post Administration Create my blog
Balavardhan Reddy Narani

Display Alert or Tooltip text On MouseOver In an ASP.NET GridView

August 5 2009 , Written by Balavardhan Reddy Published on #ASP.Net


We can display a Alert message or 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');");
     }
}





--

Share this post

Repost 0

Comment on this post

Serge Travnikov 06/08/2012 17:12


 


 


 


Why should not you use that: