Best Way to Find Check Boxes on a DataList

Discussion in 'ASP .Net' started by Fao, Sean, Jan 25, 2006.

  1. Fao, Sean

    Fao, Sean Guest

    I've been using the following technique to locate CheckBoxes on a DataList:

    private void Button1_Click(object sender, System.EventArgs e)
    {
    CheckBox checkbox;

    foreach (DataGridItem dgitem in this.AuthorsDataGrid.Items)
    {
    if ((checkbox = (CheckBox) dgitem.FindControl("DataGridCheckBox"))
    != null)
    System.Diagnostics.Debug.WriteLine("found it...");
    else
    System.Diagnostics.Debug.WriteLine(dgitem.ID);
    }
    }

    The only real flaw (that I know of) using this technique is that it
    breaks if anybody changes the ID of the CheckBox controls on the DataList.

    Is this an acceptable technique? Is there a better way?

    Thank you in advance,

    --
    Sean
     
    Fao, Sean, Jan 25, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kris
    Replies:
    0
    Views:
    515
  2. kris
    Replies:
    0
    Views:
    480
  3. kris
    Replies:
    1
    Views:
    5,210
  4. Suresh
    Replies:
    2
    Views:
    399
    Suresh
    Apr 22, 2004
  5. pw

    Check All Check Boxes

    pw, May 24, 2005, in forum: Javascript
    Replies:
    8
    Views:
    135
    Lasse Reichstein Nielsen
    May 25, 2005
Loading...

Share This Page