.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Windows Application >> Post New QuestionBookmark and Share Subscribe to Forum

About ArrayList

Posted By: subash     Posted Date: June 05, 2009    Points:2   Category :Windows Application
hi
In my form contains,a groupbox which contains 10 checkboxes.how to select all the checkboxes using arraylist.Because,if i check single checkbox means,a group of values are stored to database.I done this.
My question is
How to select all checkboxes (or) two or more check boxes and click save button,the group of values are stored into the database corresponding to the selected checkbox

Thanks
Subash

Responses
Author: Amit Mehra             
Posted Date: June 05, 2009     Points: 5   

Hi,
I dont think you need arraylist for that here is the solution you can loop through the page like this and get the checkbox checked value


string allCheckBoxValues = "";
foreach (Control c in Page.Controls)
{
foreach (Control childc in c.Controls)
{
if (childc is CheckBox)
{
if(childc.Checked)
{
allCheckBoxValues += ((CheckBox)childc).Text + ",";
}
}
}
}
if allCheckBoxValues != "")
{
// Your database call goes here
}


Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: subash             
Posted Date: June 05, 2009     Points: 5   

Thank u for the coding
Then am asking for windows applications

Please send me the code for windows application

Author: subash             
Posted Date: June 05, 2009     Points: 5   

For label Property
objSam.ControlForeColor = ulbl1.ForeColor.ToString();
objSam.ControlBackColor = ulbl1.BackColor.ToString();
objSam.ControlFontName = ulbl1.Font.Name.ToString();
objSam.ControlFontSize = ulbl1.Font.Size.ToString();
objSam.ControlFontStyle = ulbl1.Font.Style.ToString();

For radiobutton property
objSam.ControlForeColor = cRadioBtn1.ForeColor.ToString();
objSam.ControlBackColor = cRadioBtn1.BackColor.ToString();
objSam.ControlFontName = cRadioBtn1.Font.Name.ToString();
objSam.ControlFontSize = cRadioBtn1.Font.Size.ToString();
objSam.ControlFontStyle = cRadioBtn1.Font.Style.ToString();

objsam is object created for DAL files
ulbl1 is label name
cRadioBtn1 is for radiobutton

so if i select chLabel checkbox and chradiobutton check box at same time .
So how can i include database code inside this if condition.Because allcheckboxvalues contains both chLbl and chRadioBtn
if allCheckBoxValues != "")
{
// Your database call goes here
}

Thanks
Suabsh

Author: Amit Mehra             
Posted Date: June 06, 2009     Points: 5   

HI Subhash,
Sorry you can use this instead pf Page in the first loop.
like this
foreach (Control c in this.Controls)
{
foreach (Control childc in c.Controls)
{
if (childc is CheckBox)
{
if(childc.Checked)
{
allCheckBoxValues += ((CheckBox)childc).Text + ",";
}
}
}
}
if allCheckBoxValues != "")
{
// Your database call goes here
}

in the above you have asked

if (allCheckBoxValues != "")
{
// Your database call goes here
}

when you loop throu the form it will ge all the reference of the control and from that it will take out the Checkbox.

Hope this will help you

Thanks,
Amit
Please "Mark As Answer " if this post help you.


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend