简体   繁体   中英

ASP.NET RadioButton | Change HTML Generated

I'm basically using asp.net controls (runat="server") and I have this code:

<div class="form-group">
<label for="RadioButtonRating" class="col-md-4 control-label">Select</label>
<div class="col-md-8">
    <asp:RadioButtonList ID="RadioButtonRating" runat="server"
    RepeatDirection="Horizontal" RepeatLayout="Table" AppendDataBoundItems="true" class="">
    </asp:RadioButtonList>
</div>

I'm inserting the radio button items dynamically by using an SQL Adapter.

My main issue is that I want to implement directly bootstrap for material design, and the code must be written differently than the code that asp.net is generated.

I want to have this:

<div class="radio radio-primary">
      <label>
        <input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked="">
        Option one is this
      </label>
</div>

Code is generated like:

<input id="MainContent_RadioButtonRating_2" type="radio" name="ctl00$MainContent$RadioButtonRating" value="3">
<label for="MainContent_RadioButtonRating_2">3</label>

I guess my main issue is to remove the "for=" from the label, and to put input between the label tags.

I guess I have two options. By stick with the asp.net radio control and dynamically change this to fit (any ideas how?). Or by taking out the asp.net radio button control (if I do this, can I still in the same form use other asp.net controls? Can I still manipulate the radio button in the code side?

It all depends if you need access to the controls properties on the sevrer side afterwards... but you could create this as a literalControl in the code behind and add add it to the controls collection of the parent element.

Here's a very crude example of adding a div panel to form...

    protected void Page_Load(object sender, EventArgs e)
    {
        LiteralControl litCon = new LiteralControl("<div>Hello</div>");
        form1.Controls.Add(litCon);
    }

Although using this, you will not have direct access to the control properties server side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM