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)
<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,