asp.net GridView和DataList實現(xiàn)鼠標移到行行變色
更新時間:2009年02月12日 20:11:46 作者:
在設(shè)計頁面添加了DataList控件后,我在使用DataList綁定數(shù)據(jù)時是通過單元格來綁定的,因此鼠標效果就在源代碼頁面去實現(xiàn)
在GridView控件的RowDataBound事件里添加以下代碼
if (e.Row.RowType == DataControlRowType.DataRow)
{
//當鼠標移到行上時更改背景色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#EE82EE'");
//當鼠標移開時還原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
在設(shè)計頁面添加了DataList控件后,我在使用DataList綁定數(shù)據(jù)時是通過單元格來綁定的,因此鼠標效果就在源代碼頁面去實現(xiàn),如下例所示
<asp:DataList ID="DataList1" runat="server" BorderWidth="1" >
<ItemTemplate>
<tr onmouseover="this.style.backgroundColor='#8EC26F'" onmouseout="this.style.backgroundColor=''" >
<td>
<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ID") %>'></asp:Label>
</td>
<td>
<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Area") %>'></asp:Label>
</td>
</tr>
</ItemTemplate>
<HeaderTemplate>
Header1</td>
<td>Header2
</HeaderTemplate>
</asp:DataList>
if (e.Row.RowType == DataControlRowType.DataRow)
{
//當鼠標移到行上時更改背景色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#EE82EE'");
//當鼠標移開時還原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
在設(shè)計頁面添加了DataList控件后,我在使用DataList綁定數(shù)據(jù)時是通過單元格來綁定的,因此鼠標效果就在源代碼頁面去實現(xiàn),如下例所示
<asp:DataList ID="DataList1" runat="server" BorderWidth="1" >
<ItemTemplate>
<tr onmouseover="this.style.backgroundColor='#8EC26F'" onmouseout="this.style.backgroundColor=''" >
<td>
<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ID") %>'></asp:Label>
</td>
<td>
<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Area") %>'></asp:Label>
</td>
</tr>
</ItemTemplate>
<HeaderTemplate>
Header1</td>
<td>Header2
</HeaderTemplate>
</asp:DataList>
您可能感興趣的文章:
- 決定何時使用 DataGrid、DataList 或 Repeater(ASP.NET 技術(shù)文章)
- asp.net Datalist控件實現(xiàn)分頁功能
- asp.net datalist 用法
- asp.net使用for循環(huán)實現(xiàn)Datalist的分列顯示功能
- asp.net DataList與Repeater用法區(qū)別
- asp.net 通過aspnetpager為DataList分頁
- asp.net 獲取Datalist中Checkbox的值的小結(jié)
- asp.net中將數(shù)據(jù)庫綁定到DataList控件的實現(xiàn)方法與實例代碼
- ASP.NET數(shù)據(jù)綁定之DataList控件實戰(zhàn)篇
相關(guān)文章
.NET全局靜態(tài)可訪問IServiceProvider的過程詳解(支持Blazor)
為解決在靜態(tài)方法中訪問依賴注入(DI)容器的問題,提出了通過DependencyInjection.StaticAccessor包實現(xiàn)靜態(tài)訪問,這一方法特別適用于需要在靜態(tài)方法中獲取范圍內(nèi)(Scoped)服務(wù)的場景,感興趣的朋友跟隨小編一起看看吧2024-09-09
MVC微信網(wǎng)頁授權(quán)獲取用戶OpenId
這篇文章主要為大家詳細介紹了MVC微信網(wǎng)頁授權(quán),在模板頁中獲取用戶openid,感興趣的小伙伴們可以參考一下2016-09-09
.Net插件框架Managed Extensibility Framework簡介
這篇文章介紹了.Net插件框架Managed Extensibility Framework,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07
.Net Core3.0 配置Configuration的實現(xiàn)
這篇文章主要介紹了.Net Core3.0 配置Configuration的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10

