asp.net GridView和DataList實現(xiàn)鼠標(biāo)移到行行變色
更新時間:2009年02月12日 20:11:46 作者:
在設(shè)計頁面添加了DataList控件后,我在使用DataList綁定數(shù)據(jù)時是通過單元格來綁定的,因此鼠標(biāo)效果就在源代碼頁面去實現(xiàn)
在GridView控件的RowDataBound事件里添加以下代碼
if (e.Row.RowType == DataControlRowType.DataRow)
{
//當(dāng)鼠標(biāo)移到行上時更改背景色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#EE82EE'");
//當(dāng)鼠標(biāo)移開時還原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
在設(shè)計頁面添加了DataList控件后,我在使用DataList綁定數(shù)據(jù)時是通過單元格來綁定的,因此鼠標(biāo)效果就在源代碼頁面去實現(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)
{
//當(dāng)鼠標(biāo)移到行上時更改背景色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#EE82EE'");
//當(dāng)鼠標(biāo)移開時還原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
在設(shè)計頁面添加了DataList控件后,我在使用DataList綁定數(shù)據(jù)時是通過單元格來綁定的,因此鼠標(biāo)效果就在源代碼頁面去實現(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)文章
asp.net(C#)使用QRCode生成圖片中心加Logo或圖像的二維碼實例
這篇文章主要介紹了asp.net(C#)使用QRCode生成圖片中心加Logo或圖像的二維碼,結(jié)合實例形式詳細(xì)分析了asp.net基于QRCode生成二維碼的具體實現(xiàn)技巧,需要的朋友可以參考下2016-06-06?ASP.NET Core 模型驗證過濾器的兩種實現(xiàn)方法
?在.Net Core的時代中,框架會幫你自動驗證,本文主要介紹了?ASP.NET Core 模型驗證過濾器的兩種實現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05asp.net 操作XML 按指定格式寫入XML數(shù)據(jù) WriteXml
從SQL下載數(shù)據(jù)到本地為XML文件2009-07-07CreateOutputCachedItemKey 緩存key的創(chuàng)建
有關(guān)OutputCache的相關(guān)資料大家可以查看 OutputCacheProvider OutputCache的一點點認(rèn)識 ,我們還是復(fù)習(xí)一下OutputCache內(nèi)容2012-11-11vs.net控件updatePanel實現(xiàn)無刷新的方法
vs.net控件updatePanel實現(xiàn)無刷新的方法,需要的朋友可以參考一下2013-04-04asp.net下獲取遠(yuǎn)程網(wǎng)頁的內(nèi)容之二(downmoon原創(chuàng))
asp.net下獲取遠(yuǎn)程網(wǎng)頁的內(nèi)容之二(downmoon原創(chuàng))...2007-04-04