asp.net GridView control mouse move a row change background color (method one) _ Practical tips

Source: Internet
Author: User
Copy Code code as follows:

Using System;
Using System.Data;
Using System.Configuration;
Using System.Collections;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;

public partial class Demo19:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
if (Page.IsPostBack = = False)
{
Binddata ();
}
}

public void Binddata ()
{
String strSQL = "Select Userid,c_name,e_name,updatadate,qq from Demo_user";
DataTable dt = SqlHelper.ExecuteDataset (sqlhelper.conn_string, CommandType.Text, strSQL, null). Tables[0];

Gridview.datasource = DT;
Gridview.datakeynames = new string[] {"UserID"};//primary key
Gridview.databind ();
}

protected void Gridview_pageindexchanging (object sender, Gridviewpageeventargs e)
{
Gridview.pageindex = E.newpageindex;
Binddata ();
}

protected void Gridview_rowdatabound (object sender, GridViewRowEventArgs e)
{
if (E.row.rowtype = = Datacontrolrowtype.datarow)
{
When the mouse passes, the row background color changes
E.row.attributes.add ("onmouseover", "This.style.backgroundcolor= ' #00A9FF");
The row background color changes when the mouse is moved
E.row.attributes.add ("onmouseout", "This.style.backgroundcolor= ' #FFFFFF");
}
}
}

<table align= "center" bgcolor= "#c0de98" border= "0" cellpadding= "0" cellspacing= "1" width= "99%" >
<tr>
<th colspan= "2" >
GridView Demo </th>
</tr>
<tr>
&LT;TD colspan= "2" style= "width:100%;" >
<asp:gridview id= "GridView" runat= "Server" width= "100%" autogeneratecolumns= "False" allowpaging= "True" onpageindexchanging= "gridview_pageindexchanging" pagesize= "onrowdatabound=" Gridview_rowdatabound ">
<Columns>
<asp:boundfield datafield= "UserID" headertext= "UserID"/>
<asp:boundfield datafield= "C_name" headertext= "Chinese name"/>
<asp:boundfield datafield= "E_name" headertext= "English name"/>
<asp:boundfield datafield= "QQ" headertext= "QQ"/>
<asp:boundfield datafield= "updatadate" headertext= "Update Time"/>
</Columns>
<rowstyle horizontalalign= "Center"/>
<pagerstyle horizontalalign= "right"/>
</asp:GridView>
</td>
</tr>
</table>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.