P. Pogba
P. Pogba

Reputation: 175

ASP.NET - How to put items of Radiobuttonlist into HTML tag

I want put items of Radiobuttonlist into td tag.

<td><asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatLayout="Table" RepeatDirection="Horizontal"></asp:RadioButtonList></td>

This is result. This is Matrix, Rows and Column is loaded from database.(RadioButtonList was set datasource). enter image description here

I put RadioButtonList into td tag: all of items is contained in a cell. My matrix will be complete when each item contained in a cell.

Have Itemtemplate for RadioButtonList like Repeater?

Upvotes: 1

Views: 970

Answers (1)

Srikanth
Srikanth

Reputation: 86

Create your own custom radiobuttonlistcontrol:

namespace Controls
{
    public class MyRadioButtonList : RadioButtonList
    {

        protected override void RenderItem(System.Web.UI.WebControls.ListItemType itemType, int repeatIndex, System.Web.UI.WebControls.RepeatInfo repeatInfo, System.Web.UI.HtmlTextWriter writer)
        {
            writer.Write("<td>");
            base.RenderItem(itemType, repeatIndex, repeatInfo, writer);
            writer.Write("</td>");
        }
    }

}

And use it as so.

First register the control to a page, or a user control:

And then use the control:

It's a basic radiobuttonlistcontrol in the server side, so just use it as you do now.

Upvotes: 1

Related Questions