Appending HTML inside datagrid cells at runtime.

J

Jared

Hello all,
I'm looking for the best way to wrap my cell contents in a html label
tag. The results I'm looking for will allow the user to select the checkbox
when any cell in the tablerow is clicked. Keep in mind that these rows are
generated by a datagrid control. I would like to use strait forward
solutions without doing a lot of unnecessary server processing.

' Before
<tr class="Row">
<td><input id="MyGrid__ctl4_chkBox" type="checkbox"
name="MyGrid:_ctl4:chkBox" /></td>
<td>Some simple text</td>
<td>Some more text</td>
</tr>

' After
<tr class="Row">
<td><input id="MyGrid__ctl4_chkBox" type="checkbox"
name="MyGrid:_ctl4:chkBox" /></td>
<td><label for="MyGrid__ctl4_chkBox">Some simple text</label></td>
<td><label for="MyGrid__ctl4_chkBox">Some more text</label></td>
</tr>

I am appending the label markup in the ItemCreated handler, is there a
better way?

' My Current Working Code - Is there a better way?
Dim id As String = e.Item.FindControl("chkBox").ClientID
For i As Integer = 1 To e.Item.Cells.Count
e.Item.Cells(i).Text = _
"<label for=""" & id & """>" _
& e.Item.Cells(i).Text & "</label>"
Next

TIA,
Jared
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top