SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    May 2006
    Posts
    457
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    check if checkbox is checked

    Im looping throug a database, for each entry I am creating a checkbox, where its ID = checkbox.ID = "check" + AlertID.ToString(); where AlertId is the PK of the database.

    Is there any way of me checking in the page_load event if the checked value of the checkbox is true or false?

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Is there any reason you are not using a repeater rather than creating a whole gaggle of checkboxes? Using normal web controls would make this operation alot easier.

  3. #3
    SitePoint Evangelist
    Join Date
    May 2006
    Posts
    457
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think uve got a point, the only reason that I didnt consider using a reapeater was because I am outputting the checkboxes into a column in a table.

    Ive tried the following as an example, but i dont think ive got it quite right yet. I dont get any values for ch.ID in the
    Code:
    CheckBox cbx = (CheckBox)ch.FindControl(ch.ID);
    line of code. Any ideas? Am I on the right lines?

    Code:
    Repeater repeater = new Repeater();
    ArrayList details = new ArrayList();
    details.Add("2");
    
            repeater.DataSource = details;
            repeater.DataBind();
    
            foreach (RepeaterItem ch in repeater.Items)
            {
                CheckBox cbx = (CheckBox)ch.FindControl(ch.ID);
                if (cbx.Checked)
                {
    
                }
            }

  4. #4
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    There is no reason you cannot wrap whatever item you are using in the repeater in a table cell, or a table row, or whatever. It is very, very free-form.

    Looking at your other code, you will actually need to search within the table cell you are creating server-side to find the checkbox. I would just start re-engineering now.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •