Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am creating multiple checkboxes dynamically. Now i want to find id & text of selected checkboxes. I have written following code. I am able to find ID but not its text.

C#
foreach (ListViewDataItem item in lvwFields.Items)
{
    PlaceHolder ph = (PlaceHolder)item.FindControl("plhldFields");
    foreach (Control c in ph.Controls)
    {
        if (c is CheckBox)
        {
            if (((CheckBox)c).Checked)
            {
                //Perform some action
                //Here i am getting c.ID
                //How to find its text?
            }
        }
        else if (c is HtmlTable)
        {
            foreach (Control TabCtrl in c.Controls)
            {
                if (TabCtrl is HtmlTableRow)
                {
                    foreach (Control TabCell in TabCtrl.Controls)
                    {
                        if (TabCell is HtmlTableCell)
                        {
                            foreach (Control chk in TabCell.Controls)
                            {
                                if (chk is CheckBox)
                                {
                                    if (((CheckBox)chk).Checked)
                                    {
                                    //Perform some action
                                    //Here i am getting chk.ID
                                    //How to find its text?
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}


Thanks
Posted
Updated 31-May-13 0:24am
v4
Comments
Can't you get c.Text ?
PleaseHelpCP 31-May-13 6:26am    
no. not getting c.Text. It shows title in <span> and creates label associated with that checkbox and shows text there
ZurdoDev 31-May-13 8:03am    
You need to reply to the comment, not add a new comment to your own question.
PleaseHelpCP 31-May-13 6:28am    
<tr>
<td>
<span title="Sample Text"><input id="lvwFields_ctrl53_.Sample_Text" type="checkbox" name="lvwFields$ctrl53$.Sample_Text" /><label for="lvwFields_ctrl53_.Sample_Text">SampleText</label></span>
</td>
</tr>
Prasad Khandekar 31-May-13 6:42am    
How are you generating the text when you dynamically create the checkbox?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900