C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

Multiple selection from checkboxes


Posted Date: 02 Jul 2009      Posted By: HEMANT      Member Level: Gold     Points: 1   Responses: 2



hi guys ,how can i select multiple values from the five checkboxes using properties in asp.net(C#). pls giv me d code in c#




Responses

Author: mohd sagir    02 Jul 2009Member Level: BronzeRating: 1 out of 5     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 2009Member Level: DiamondRating: 2 out of 52 out of 5     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



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Question for webdesigners
Previous : Code working properly in internet explorer 7 but not in internet explorer 8
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use