Highlighting GridView Row on MouseOver

Of late , i've  been receiving  E-Mails  asking for  publishing  the content  for BEGINNERS  in  .NET ,  So  i've decided  to  include  some  new posts  for  them .

 

In  this  article  , we'll  see  how  we  can  change  the  row color  of  a  GridView  when   anyone   moves  their mouse over  the GridView .  So  let's get it  started.

1) Create  a  page name Test.aspx

 

Test.aspx ( HTML Markup)

 <div class="TEST">
    <asp:GridView  ID="GV1" runat="server" >
        <Columns>
                  <asp:TemplateField>
                          <ItemTemplate>
  
                                 <asp:LinkButton ID="Link1"  runat="server" Text='<%# Eval("FirstName") %>' CommandName="LINK"   ></asp:LinkButton>
                         </ItemTemplate>
                  </asp:TemplateField>
       </Columns>
    </asp:GridView>
       
  </div>

 

Test.aspx.cs

protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            con = new SqlConnection("uid=sa;pwd=123456;database=Talib");
            con.Open();
            da = new SqlDataAdapter("select  * from tblRegistration order by id desc", con);
            ds = new DataSet();
            da.Fill(ds);
            GV1.DataSource = ds;  // GV1 is  the name of  GridView
            GV1.DataBind();
        }

        catch (Exception ex)
        {
            Response.Write(ex.Message);

        }
        finally
        {
            con.Close();
        }

    }

 

2)  Now  we  need to  assign  the  CSS  styling  for this   GridView  ,  illustrated  below

<style type="text/css">
        .TEST div table tr:hover
    {
          background-color:silver;
    }

</style>

 

Now, we're done.  Execute  the  page  and  see how  it  works.

 

 

I  hope you people like this post ,till  then  enjoy  Programming ......   Smile

 


Tags: , , , , ,
Categories: ASP.NET

17 Comments
Actions: E-mail | Permalink | Comment RSSRSS comment feed

 


© Copyright 2009. www.onlineasp.net All Rights Reserved.