Best Way to Find Check Boxes on a DataList

F

Fao, Sean

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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top