怎样给ListBox控件的选中项改变文本颜色或增加背景色(C#语言)? 我用三个ListBox控件做联动的分类程序,测试是已经通过了,可以的。但是现在最烦人的是无法给选中的项改变文本颜色或增加背景色,以方便用户很直观的看到他所选择的分类。请教一下大师们是怎么做的?我在网上怎么找都找不到相关资料呀! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 this.listBox1.DrawMode = DrawMode.OwnerDrawFixed; 然后在listBox1的DrawItem事件中处理。具体代码查一查DrawItem的帮助 因为选中的Item的Style是无法改变的.所以要自定义选中Item的Style.只有先将选中的Item的相关信息保存起来,然后再将它设为不选中,最后再设置此Item的Style.<html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>未命名頁面</title> <script language="javascript" type="text/javascript"> //Selected="True" function ListBox1_OnChange() { var ls = document.getElementById('ListBox1'); //将所有Item的Style还原. for(var i=0;i<ls.options.length;i++) { ls.options[i].style.backgroundColor = 'white'; ls.options[i].style.color = 'black'; } //给选中的Item设定自定义的Style. ls.options[ls.selectedIndex].style.backgroundColor = 'yellow'; ls.options[ls.selectedIndex].style.color = 'red'; //先将选中的Index存到某个地方(比如:hidden,隐藏的Label......). //最后将SelectedItem清空. ls.selectedIndex = -1; } </script></head><body> <form id="form1" runat="server"> <div> <asp:ListBox ID="ListBox1" runat="server" onchange="ListBox1_OnChange()"> <asp:ListItem>1</asp:ListItem> <asp:ListItem >2</asp:ListItem> <asp:ListItem>3</asp:ListItem> </asp:ListBox></div> </form></body></html> 我在作买商品处理时,要用到缓存处理,日志缓存我在网上找了个代码。不明白意思就问下各位高手 不懂gridview,请高手帮助 继承泛型抽象类 TCPclient.Available 自动返回数据 C# TCP 协议 高分请解数字正则表达式。 我们现在在网上常玩的 B/S方式游戏,一般都是用什么语言或工具开发的? 各位老大:怎么解决发送C#发送Email附件的问题啊?拜托了!我找不出来原因啊!!求救!! C#中如何获取鼠标坐标? C# 遍历右键二级菜单 如何将服务器控件值赋给客户端?自已搞了很多天也没搞定,求助 这个问题出在什么地方? 哪个有购物车的代码?
然后在listBox1的DrawItem事件中处理。具体代码查一查DrawItem的帮助
所以要自定义选中Item的Style.
只有先将选中的Item的相关信息保存起来,然后再将它设为不选中,最后再设置此Item的Style.<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>未命名頁面</title>
<script language="javascript" type="text/javascript">
//Selected="True"
function ListBox1_OnChange()
{
var ls = document.getElementById('ListBox1');
//将所有Item的Style还原.
for(var i=0;i<ls.options.length;i++)
{
ls.options[i].style.backgroundColor = 'white';
ls.options[i].style.color = 'black';
}
//给选中的Item设定自定义的Style.
ls.options[ls.selectedIndex].style.backgroundColor = 'yellow';
ls.options[ls.selectedIndex].style.color = 'red';
//先将选中的Index存到某个地方(比如:hidden,隐藏的Label......).
//最后将SelectedItem清空.
ls.selectedIndex = -1;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="ListBox1" runat="server" onchange="ListBox1_OnChange()">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem >2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:ListBox></div>
</form>
</body>
</html>