实现onmouseover和onmouseout应用于RadioButtonList或CheckBoxList控件上
一直想实现onmouseover和onmouseout应用于RadioButtonList或CheckBoxList控件上,今晚终于有时间实现它。此功能就是当鼠标经过时RadioButtonList或CheckBoxList每一个Item时,让Item有特效显示,离开时,恢复原样。可以看到效果:
RadioButtonList效果:
CheckBoxList效果:
这资实现数据,Insus.NET准备了五行(Five Phases)
创建一个对象[Five Phases]:
FivePhases.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for FivePhases
/// </summary>
public class FivePhases
{
private int _ID;
private string _Name;
public int ID
{
get { return _ID; }
set { _ID = value; }
}
public string Name
{
get { return _Name; }
set { _Name = value; }
}
public FivePhases()
{
//
// TODO: Add constructor logic here
//
}
public FivePhases(int id, string name)
{
this.ID = id;
this._Name = name;
}
}
private List<FivePhases> GetFivePhases()
{
List<FivePhases> ListFH = new List<FivePhases>();
FivePhases fh = new FivePhases();
fh.ID = 1;
fh.Name = "木";
ListFH.Add(fh);
fh = new FivePhases();
fh.ID = 2;
fh.Name = "火";
ListFH.Add(fh);
fh = new FivePhases();
fh.ID = 3;
fh.Name = "土";
ListFH.Add(fh);
fh = new FivePhases();
fh.ID = 4;
fh.Name = "金";
ListFH.Add(fh);
fh = new FivePhases();
fh.ID = 5;
fh.Name = "水";
ListFH.Add(fh);
return ListFH;
}
此时,你可以拉一个RadioButtonList或是CheckBoxList控件至网页中,此例以RadioButtonList控件为例。
<asp:CheckBoxList ID="RadioButtonListFivePhases" runat="server" RepeatDirection="Horizontal"></asp:CheckBoxList>
然后在cs绑定数据:
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Data_Binding();
}
private void Data_Binding()
{
this.RadioButtonListFivePhases.DataSource = GetFivePhases();
this.RadioButtonListFivePhases.DataTextField = "Name";
this.RadioButtonListFivePhases.DataValueField = "ID";
this.RadioButtonListFivePhases.DataBind();
}
}
还得准备鼠标的over与out样式:
<style type="text/css">
.overStyle {
font-weight: bold;
color: #f00;
}
.outStyle {
font-weight: normal;
color: none;
}
</style>
在Javascript中实现每个Item有onmouseover和onmouseout事件,因此还得写Javascript脚本,放于<head>内。
<script type="text/javascript">
function windowOnLoad() {
var rbl = document.getElementById('<%= RadioButtonListFivePhases.ClientID %>');
var labels = rbl.getElementsByTagName('label');
for (var i = 0; i < labels.length; i++) {
var lbl = labels[i];
lbl.onmouseover = function () {
this.className = 'overStyle';
};
lbl.onmouseout = function () {
this.className = 'outStyle';
};
}
}
window.onload = windowOnLoad;
</script>
相关文章
ASP.NET中CheckBoxList复选框列表控件详细使用方法
本文主要介绍CheckBoxList几种常见的用法,并做出范例演示供大家参考,希望对学习asp.net的朋友有所帮助。...2021-09-22- gridview和checkboxlist的嵌套使用,会有效的提高开发的效率,不过很多的童鞋们对此还是很陌生的,接下来将帮助童鞋们实现gridview和checkboxlist的嵌套使用,感兴趣的朋友可以了解下,或许对你有所帮助...2021-09-22
- 用CheckBoxList实现单选的原因是我觉得CheckBoxList控件页面展示效果要好看一些,需要的朋友可以参考下...2021-09-22
ASP.NET服务器端控件RadioButtonList,DropDownList,CheckBoxList的取值、赋值用法
这三个控件都有一个Items集合,可以用 RepeatLayout 和 RepeatDirection 属性来控制列表的呈现形式...2021-09-22ASP.NET中RadioButtonList绑定后台数据后触发点击事件
这篇文章主要介绍了ASP.NET中RadioButtonList绑定后台数据后触发点击事件的相关资料,感兴趣的小伙伴们可以参考一下...2021-09-22如何为CheckBoxList和RadioButtonList添加滚动条
这篇文章主要介绍了为CheckBoxList和RadioButtonList添加滚动条的方法,感兴趣的小伙伴们可以参考一下...2021-09-22- 这篇文章主要为大家详细介绍了ASP.NET控件之RadioButtonList的使用方法,感兴趣的小伙伴们可以参考一下...2021-09-22
RadioButtonList绑定图片及泛型Dictionary应用
读取站点某一目录的图片,需要掌握LINQ与泛型Dictionary<TKey,TValue>的使用,本文将介绍RadioButtonList绑定图片的实现,感兴趣的朋友可以了解下,或许对你有所帮助...2021-09-22实现onmouseover和onmouseout应用于RadioButtonList或CheckBoxList控件上
一直想实现onmouseover和onmouseout应用于RadioButtonList或CheckBoxList控件上。此功能就是当鼠标经过时RadioButtonList或CheckBoxList每一个Item时,让Item有特效显示,离开时,恢复原样有演示动画,感兴趣的朋友可以了解下啊...2021-09-22ASP.NET中用js取CheckBoxList中值的方法实例
用脚本取CheckBoxList中的值,并用"|"将其分开,之后将取到的值放入文本框,返回数据库做添加或者修改...2021-09-22读取XML并绑定至RadioButtonList实现思路及演示动画
读取XML的文档,可以使用System.Data.DataSet类别中的ReadXml()方法,在aspx网页上拉一个RadioButtonList控件,用来显示XML的数据,接下来,用DataSet去读取刚才写好的获取XML文件的属性,即可完成...2021-09-22javascript判断是否有对RadioButtonList选项选择
写个Javascript来判断是否有对RadioButtonList选项选择,附动画演示,感兴趣的朋友可以了解下,希望对您们有帮助...2021-09-22ASP.NET中 RadioButtonList 单选按钮组控件的使用方法
本文主要简单介绍RadioButtonList控件的常见属性和使用方法,希望对大家有所帮助。...2021-09-22asp.net CheckBoxList各项最小宽度CSS样式(兼容性good)
ASP.NET中,CheckBoxList里的选择都是自动宽度的,属性时没有设置各项宽度的设置,在IE10、遨游4极速模式及兼容模式下均可正确显示最小宽度,此样式除了用于CheckBoxList外,也可用于DIV等...2021-09-22- CheckBoxList两列并排的显示效果相比大家都有见到过吧,下面是具体的实现代码,感兴趣的朋友可以参考下哈...2021-09-22
asp.net使用jQuery获取RadioButtonList成员选中内容和值示例
这篇文章主要介绍了通过jQuery来获取RadioButtonList成员内容的方法,大家参考使用吧...2021-09-22