| Author: mohd sagir 02 Jul 2009 | Member Level: Bronze | Rating: Points: 1 |
public class TriStateCheckBox : WebControl
{
// Member variables
//
string _DefaultState = "1";
string _DefaultAction = "1";
string _name = string.Empty;
string _imagespath = "images/";
CheckBoxTableStyle _CheckBoxStyle = CheckBoxTableStyle.classic;
// Public properties
//
public string DefaultState
{
get { return _DefaultState; }
set { _DefaultState = value; }
}
public string DefaultAction
{
get { return _DefaultAction; }
set { _DefaultAction = value; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
public string ImagePath
{
get { return _imagespath; }
set { _imagespath = value; }
}
// Behavior
//
public enum CheckBoxTableStyle
{
classic,
flat,
xp
}
public CheckBoxTableStyle CheckBoxStyle
{
get { return _CheckBoxStyle; }
set { _CheckBoxStyle = value; }
}
private string Build()
{
string script = "<script>";
script += "function settristate(obj)";
script += "{";
script += "var temp='';";
script += "var _obj=document.getElementById('value_'+obj);";
script += "temp = _obj.innerHTML;";
script += "if(temp == '1')";
script += "{";
script += "document.getElementById('tristate_'+obj).src = '" + ImagePath + "2.bmp/';";
script += "document.getElementById('value_'+obj).innerHTML = '2';";
script += "}";
script += "if(temp == '2')";
script += "{";
script += "document.getElementById('tristate_'+obj).src = '" + ImagePath + "3.bmp';";
script += "document.getElementById('value_'+obj).innerHTML = '3';";
script += "}";
script += "if(temp == '3')";
script += "{";
script += "document.getElementById('tristate_'+obj).src = '" + ImagePath + "1.bmp';";
script += "document.getElementById('value_'+obj).innerHTML = '1';";
script += "}";
script += "}";
script += "function GetValues(obj){var ret = document.getElementById('value_'+obj).innerHTML;return ret;}";
script += "function GetActions(obj){var ret = document.getElementById('accion_'+obj).innerHTML;return ret;}";
script += "</script>";
return script;
}
// Render tristatecheckbox
//value_x is the current value of the checkbox "x"
//action_x is the custom action for checkbox "x"
protected override void Render(HtmlTextWriter output)
{
output.Write("<IMG id='tristate_" + Name + "' onclick=settristate('" + Name + "') src='" + ImagePath + _DefaultState + ".bmp'>");
output.Write("<span id='value_" + Name + "' style='VISIBILITY: hidden' name='value_" + Name + "'>3</span>");
output.Write("<span id='accion_" + Name + "' style='VISIBILITY: hidden' name='accion_" + Name + "'>" + DefaultAction + "</span>");
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(Build());
}
|
| Author: Anil Kumar Pandey 03 Jul 2009 | Member Level: Diamond | Rating:  Points: 2 |
hi, use the for loop or for each loop
check for each value if that check box is checked you can get it value and can store in an array..
Thanks & Regards Anil Kumar Pandey
|