Rewrite HTML Output of ASP.NET Control

I am using standard ASP.NET CheckboxList control in a page.

<asp:CheckBoxList ID="lstNames" runat="server" RepeatColumns="1" RepeatDirection="Vertical" RepeatLayout="Flow"/>

Open in new window


The output in HTML is
<span id="lstNames">
<input id="lstNames_0" type="checkbox" name="lstNames$0" value="4554" />
    <label for="lstNames_0">Aka</label><br />
<input id="lstNames_1" type="checkbox" name="lstNames$1" value="4546" />
    <label for="lstNames_1">Joe</label><br />
<input id="lstNames_2" type="checkbox" name="lstNames$2" value="4548" />
    <label for="lstNames_2">Joy</label><br />
<input id="lstNames_3" type="checkbox" name="lstNames$3" value="4545" />
    <label for="lstNames_3">Pai</label><br />
<input id="lstNames_4" type="checkbox" name="lstNames$4" value="4550" />
    <label for="lstNames_4">Susan</label><br />
<input id="lstNames_5" type="checkbox" name="lstNames$5" value="4551" />
    <label for="lstNames_5">Zoe</label></span>

Open in new window


However, I need the html output to be something like

<li><label for="lstNames_0"><input id="lstNames_0" type="checkbox" name="lstNames$0" value="4554" />
    Aka</label></li>
<li><label for="lstNames_1"><input id="lstNames_1" type="checkbox" name="lstNames$1" value="4546" />
    Joe</label></li>
<li><label for="lstNames_2"><input id="lstNames_2" type="checkbox" name="lstNames$2" value="4548" />
   Joy</label></li>
<li><label for="lstNames_3"><input id="lstNames_3" type="checkbox" name="lstNames$3" value="4545" />
    Pai</label></li>
<li><label for="lstNames_4"><input id="lstNames_4" type="checkbox" name="lstNames$4" value="4550" />
    Susan</label></li>
<li><label for="lstNames_5"><input id="lstNames_5" type="checkbox" name="lstNames$5" value="4551" />
    Zoe</label></li>

Open in new window


Anyway to rewrite the output? Or have to make a custom control?
LVL 1
David_zuAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SammyCommented:
You can not rewrite the single control html without having to rewrite the control itself.
you can however use Response.Filter to intercept the full response and rewrite its content. In your case, I highly recommend against rewriting the the full Response content and rewrite the control.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rainer JeschorCommented:
Hi,
+1 for rewriting / using a custom control if you want / have to do it on the server side.

If you (can) use jQuery AND can / want to do it on the client side, this would also be possible with jQuery (also with plain Javascript but a little bit more complicated).

HTH
Rainer
David_zuAuthor Commented:
OK... Then I think I have to rewrite a custom control. Anyway thanks for your advice.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.