应用CheckBoxList项目的样式 [英] Apply style of CheckBoxList Item

查看:166
本文介绍了应用CheckBoxList项目的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
如何更改CheckBoxList项目文本的颜色?
例如:chkblstRoleFunc1.Attributes.Add("style", "color:red");

但是对于上述ex,红色应用于CheckBoxList的所有项目的文本.我希望它仅适用于所有项目中的一个项目,即红色仅适用于一个项目,而其余所有项目均采用黑颜色(默认颜色).


请帮助我获取有关上述问题的以下代码:
要更改CheckBoxList的样式,我已经从Code Behind调用了javascript.
问题是,
1)以下对Javascript的书面调用不起作用.
2)还请让我知道这是否是更改CheckBoxList项目样式的正确方法(代码)吗?

请看下面给出的代码:

1)背后的代码:-

Hello,
How to change colour of CheckBoxList Items Text ?
Ex: chkblstRoleFunc1.Attributes.Add("style", "color:red");

But For above ex, red colour is applied to the Text of all the Items of CheckBoxList. I want it to be applicable for only one Item among all the Items i.e. Red Colour for only one Item and rest all Items in Black Colour(which is the default colour).


Please help me out for the following code regarding Above Problem:
To Change the style Of CheckBoxList, I have called javascript from Code Behind.
Problem is that,
1) below written call to Javascript is not Working.
2) Also Let me know whether this is the right way(code) of Changing the Style of Item of CheckBoxList ?

Please have a look at the below given code :

1) Code Behind :-

if (ds1.Tables[0].Rows.Count != 0)
{
for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
{
      chkblstRoleFunc1.Items.Insert(i, new     ListItem(ds1.Tables[0].Rows[i].ItemArray[3].ToString(), ds1.Tables[0].Rows[i].ItemArray[1].ToString()));

if (Convert.ToInt32(ds1.Tables[0].Rows[i].ItemArray[2]) == 0)
{
      chkblstRoleFunc1.Attributes.Add"onload",    javascript:setCheckboxColor(''" +  ds1.Tables[0].Rows[i].ItemArray[3].ToString() + "'')");
}
}
}



2)



2)

<style type="text/css">
.selectedCheckbox
{
color: Red;
}
</style>









<script type="text/javascript">
function setCheckboxColor(selected) {
var chkList = document.getElementById('<%=chkblstRoleFunc1.ClientID%>').getElementsByTagName('label');
alert('HI');
for (var c = 0; c < chkList.length; c++) {

chkList[c].className = 'selectedCheckbox';

}

}

</script>



在此先感谢,



Thanks In Advance,

推荐答案

尝试:
一个人可以访问一个单独的项目并进行处理.这是为此需要做的:
我们需要为CheckListBox定义一个Databound 处理程序.在数据绑定期间,执行将通过此方法进行.
Try:
One can access an individual item and work on it. This is what one need to do for it:
We need to define a Databound handler for the CheckListBox. During databind, the execution will go through this method then.
protected void lstMultipleValues_DataBound(object sender, EventArgs e)
{
    foreach (ListItem item in lstMultipleValues.Items)
    {
        //check anything out here, select specific ones like
        if (item.Text.StartsWith("B"))
           item.Attributes.Add("style", "color:red");
    }
}


这篇关于应用CheckBoxList项目的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆