how to check if a check box created in runtime checked or not?

I have a webform that have mutiple collectios of check boxes created on run time ( database driven)

what is the best way to loop between them and get which ones has been checked by a user and save the results back to the database

below a portion of my code. i am adding the checkbox to cell table which added to a row, then to a table, finlally the table added to a place holder

while (drProfileList.Read())

{

HtmlTableRow tr = new HtmlTableRow();

HtmlTableCell tc = new HtmlTableCell();

CheckBox chkbox = new CheckBox();

chkbox.ID = drProfileList["RoleID"].ToString();

chkbox.Text = drProfileList["RoleName"].ToString();

tc.Controls.Add(chkbox);

tr.Cells.Add(tc);

tblExtProfile.Rows.Add(tr);

}

 

phExternal.Controls.Add(tblExtProfile);

 

 

0
aramadan66
9/21/2008 1:25:37 AM
asp.net.web-forms 93655 articles. 5 followers. Follow

6 Replies
1013 Views

Similar Articles

[PageSpeed] 19

foreach(control c in page.controls)

{

if( c is checkbox)

  checkbox x =(checbkox)c;

if(c.checked)

blablbla 


 


Don't forget to click "Mark as Answer" on the post that helped you.
Luis Esteban Valencia - Medellin - Colombia
http://wantmvp.blogspot.com/
MCP, MCTS SQL 2006, MCTS WEB APP, MCTS WINFORMS, MCTS DISTRIBUTED, NEXT MCPD ENTERPRISE APPLICATION DEVELOPER
0
levalencia
9/21/2008 1:42:28 AM

Thanks, i tried teh way that you suggest, it did not work, keep in mind that all of these check boxex created dynamically.

do i have to add some attribute like runat="server"? am i not sure what i am missing

can yo please help

thanks

0
aramadan66
9/21/2008 3:41:50 AM

 It won't work because your checkboxes are not persisted when you postback the data. YOu could do this the proper way by saving your checkboxes in the viewstate on the pre-render method of the page, or a quick way is use the Request.Form object to loop through your checkboxes. You would have to name your checkboxes with some form of identification to make it easier. For example, append your id with a "_cb" so that when you loop though the Request.Form dictionary, everytime you find a name if a "_cb" you would know that this is a checkbox and to just grab the value.

foreach (string key in Request.Form.Keys)
        {
            if (key.Contains("_cb"))
            {
                string val = Request.Form[key];
                // do some more
            }
        }

0
ed_ajax_guy
9/21/2008 4:04:46 AM

thanks, can you an example for how to use viewstate

this the way i am creating the checkbox in runtime with the page load event

really appreciated

 

 

0
aramadan66
9/21/2008 4:35:24 AM

All what i need is to check if the check box is checked, and then save to the Database. i do not want to retain the values when the page post back.

 am still not clear how can i acheive this.

i really need help, thsi is critical for me

thanks 

 

 

0
aramadan66
9/21/2008 6:46:21 AM

 while (drProfileList.Read())

{

HtmlTableRow tr = new HtmlTableRow();

HtmlTableCell tc = new HtmlTableCell();

CheckBox chkbox = new CheckBox();

chkbox.ID = drProfileList["RoleID"].ToString() + "_cb";

chkbox.Text = drProfileList["RoleName"].ToString();

tc.Controls.Add(chkbox);

tr.Cells.Add(tc);

tblExtProfile.Rows.Add(tr);

}

 

phExternal.Controls.Add(tblExtProfile);

 

***** On Postback ***

foreach ( string key in Request.Form ) {

   if ( key.Contains( "_cb" ) ){

      bool isChecked = Convert.ToBoolean( Request.Form[ key ] )
      // save this value to the database
      ....
   }

}

 

0
ed_ajax_guy
9/21/2008 7:57:33 PM
Reply:

Similar Artilces:

How to check how many check boxes are checked in the gridview
I am trying to make a javascript client fucntion to restrict no more then two rows could be selectedI have following in the itemtemplate of the gridview [although it is telerik control but same technique should be applied] <radG:GridTemplateColumn UniqueName="chkCheck">                    <HeaderStyle  HorizontalAlign="Right" />                    <HeaderTempla...

Check All Check Box While Check Header CheckBox
 hello...I have two grid on same page...both grid contains header checkbox and item checkbox i want that if use check header checkbox then all item check box checked,i have javascript for this functinality but problem is that when i click on header check box of first grid then checkbox of second grid also checked that i dnt want i want to perform this operation on one grid at one time.i have attache my script also...plz help me....thanks<script type="text/javascript">        function SelectAll(ID)      &nbs...

Check-in/Check-out
I'm having some difficulty with powerbuilder's check-in/check-out operation. When I check an object back in, the .pbl the object is being moved from is destroyed. Has anyone else experienced this and is there a fix? Cheers, Tom Thomas F. (Tom) Massey wrote: > > I'm having some difficulty with powerbuilder's check-in/check-out > operation. When I check an object back in, the .pbl the object is > being moved from is destroyed. > > Has anyone else experienced this and is there a fix? > > Cheers, > > Tom The prob...

Check out/check in
Hello How can i use the process check out/check in in PowerBuilder 8.0.3 ? We work in network. The Source Control is PB Native. I don't understand what is the parameters of Source Control ? Thank you Better to ask this in the source control group. Lots of posts on PBNative -- Evita Chapa Senior Systems Analyst II Command Technologies Inc. <Herv� Bareth> wrote in message news:3f69678e.7b3a.846930886@sybase.com... > Hello > > How can i use the process check out/check in in PowerBuilder > 8.0.3 ? We work in network. The Source Control is PB Native. ...

Check in
Hi all. I am migrating from PB 7.0 to PB 10.5, After migrating my first application i am trying to work on my first window but i'am not able to find out the way to CHECK it OUT. Wher do i can find "check out/check in" functions ?? TIA Mario Parietti What source control are you using? Have you configured it? Right click on your Workspace and check the source control tab to see if you've got it set up. "Mario Parietti" <mparietti@intercad.ch> wrote in message news:451283e0$1@forums-1-dub... > Hi all. > I am migrating from PB...

Check In/Check out
I am using PowerBuilder 9. The undo check out is right next to the check in. This is a big problem! I so easy to select Undo check out and lose all of your changes. I lost 8 hours of work yesterday because of it. I know I should be more careful. However, there should be a "Are you sure" some where also. PLEASE FIX!!!!!!!!!!!!! -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ This isn't the tech support line, it's an end-user forum. If you want to report a bug, use CaseXpress and either open a case or report a bug ...

Check In Check Out
I have some source code that I need to modify and it was sent to me in a Registered status. Therfore, when I open any object it says " 'object name' is registered but not checked out and therefore can not be overwritten. Open anyway?" Then when I try to check it out, I get "PBNative checkout not allowed for registered objects." How can I get around this? When I look under the "Source" menu, all the items concerning registered are grayed out. TIA Option1:Copy the object(Only) to someother pbl and try . Option2:If You have any SCC Expo...

Check out/check in
Hello How can i use the process check out/check in in PowerBuilder 8.0.3 ? We work in network. The Source Control is PB Native. I don't understand what is the parameters of Source Control ? Thank you Have you looked the PB8 User's guide? Chapter 3 talks about source control. -- Evita Chapa Senior Systems Analyst II Command Technologies Inc. <Herv� Bareth> wrote in message news:3f69ba0a.592b.846930886@sybase.com... > Hello > > How can i use the process check out/check in in PowerBuilder > 8.0.3 ? We work in network. The Source Control is PB Na...

Checked=Checked
 I am dynamically writing out checkboxes on a page.  I have 2 link buttons on the page that sets a boolean variable to True or False. This boolen is set in Page_PreInit and is used to Select or Deselect all the Checkboxes as they are written out. A Select ALL, Deselect ALL type of thing. At least that is the plan. As the page is being written out I do this for each checkbox and then add it to a table cell control that it added to a table row and on. tc is the table cell.  Dim chkItem As CheckBox = New CheckBox chkItem.ID = "chkRecommend" + drMember("ID")...

Java script popup dialog box when a check box control is checked. How to do with a check box?
 I have a checkbox named cbxGetInfo. If someone checks the checkbox, I want to a popup dialog box confirming the action that will be done because of the checkbox being checked. A few months ago, I used a Java Script popup dialog box for a confirmation on an action being done. Now I need to figure out how to do this for when a check box has been checked. Can someone tell me what I am doing wrong. Here is the code I place in my C# code.    cbxGetInfo.Attributes.Add("onchecked", "javascript:if(confirm('Are you sure you want to delete this record?...

Checking Check Boxes
I've got a page that edits user permissions that I'm porting from PHP. When the page loads, I need the site to load a checkbox list with the name of the various items and the IDs as the value. This is easy. However, I also need it to check off the selected items. This information is stored in a seperate database table. Using a JOIN I can write a query that will return the page id, the page name, and the permissions of the user fairly easily. However, I don't know what attribute to set in order for appropriate boxes to be checked when the page loads. I'm posting this in the PHP m...

How to check for the existing user in database and using custom validator how to check check box is checked or not?
Hi Friends, For Registration page i want to check if that user already exist in database or not? and i also have to check if user have check the checkbox for i agree then only he will be able to complete registration. here i am sending my design. and all validation i have done all validation except these two.<html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PRIZE MLS</title><link href="css/style.c...

Check Box changes other check boxes
Hi, I have a question concerning changing a check box without doing a post back on the page. I would like to do something like this: Public Sub checkAll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles checkAll.CheckedChanged If checkAll.Checked = False Then    checkVisio.Checked = True    checkPPT.Checked = True    checkRawArt.Checked = True    checkFlatArt.Checked = True Else    checkVisio.Checked = False    checkPPT.Checked = False    checkRawArt.Checked = F...

check to see if check box is checked onclientclick button event.
i have a check box similiar to "please check the box if you have read and understand what i placed there".  Right now i have the submit button doing a postback and checking to see if the checkbox is checked. great but inefficient.  I would like to use the onclientclick to check if the checkbox is checked and if not alert the user to check the box.  Thank you in advance and your help is appreciated.  I am very new to this javascript stuff so please spare me.  I am keeping the code inside my aspx file, not in codebehind. Jake You should look at using a validatio...

Web resources about - how to check if a check box created in runtime checked or not? - asp.net.web-forms

I Created Disco - Wikipedia, the free encyclopedia
I Created Disco is the debut album by Scottish recording artist Calvin Harris . It was released on 15 June 2007 by Columbia Records , preceded ...

Facebook Page Like Ads Can Now Be Created Directly Via Admin Panels On Pages
The new advertising features continue to flow out of Menlo Park, Calif. , as Facebook announced that page administrators can now create page ...

Yann LeCun - Big news today! Facebook has created a new... - Facebook
Big news today! Facebook has created a new research laboratory with the ambitious, long-term goal of bringing about major advances in Artificial... ...

Facebook: More than 200M ‘Say Thanks’ videos created
... photos and memories, people jumped at the chance. Facebook announced today that more than 200 million Say Thanks videos have been created. ...

Andy Rachleff of Benchmark Capital claims that annually, there are 15 technology companies created that ...
Answer (1 of 3): Unfortunately I never published this research. It was prepared for a speech I gave a number of years ago and then updated. That ...

RealTimes (with RealPlayer): Stories created from your photos & videos automatically on the App Store ...
Get RealTimes (with RealPlayer): Stories created from your photos & videos automatically on the App Store. See screenshots and ratings, and read ...

All eggs are created equal (NOT) - Flickr - Photo Sharing!
These are from chicken who roam around real grass meadows, not in small outdoor pens. The chocolate mousse definitely will not go poof ;-) How ...

Project Resume created by FCB Ulka for Salaam Bombay Foundation - YouTube
Project Resume is a simple yet effective solution to bridge the gap between the client’s objective (more funds for the cause) and companies looking ...

IMF warns GCC countries of $175 billion hole created by falling oil prices
The IMF believes that lower oil prices could knock nearly 1 percentage point off economic growth rates in GCC countries.

Court strikes down anti-cyberbullying law created after Rehtaeh Parsons's death
The Supreme Court of Nova Scotia has struck down an anti-cyberbullying law passed in response to the death of Rehtaeh Parsons, calling the legislation ...

Resources last updated: 12/22/2015 4:57:24 AM