Workaround for bug Q316495

Discussion in 'ASP .Net Building Controls' started by Mark Miller, Jul 30, 2003.

  1. Mark Miller

    Mark Miller Guest

    I tried posting the following to the aspnet group and got no response. I am
    on a tight deadline and it is a small detail in the overall picture but it
    is still important to the design. Please I need help.


    I have a datagrid where I need to display a list of radiobuttons for each
    row. Unfortunatly, RadioButtonList does not meet my requirements because I
    need some flexibilty for formatting. So, I added a Repeater control (I tried
    Repeater and DataList) to a TemplateColumn to display the list of radio
    buttons. Here is an example:
    <asp:DataList id="dlPrintFormat" runat="server">
    <td><input type="radio" name="radFormat"
    runat="server" value="somevalue"><asp:Label runat="server"
    id="lblFormatDescription" text='databoundtext'/></td>
    <td><asp:Label runat="server" id="lblPrice"

    Unfortuanetly the aforementioned bug does not allow a mutually exclusive set
    of radio buttons inside of a repeater, datalist or datagrid (for more
    details see Q316495). The third thing I tried (and I am really struggling
    with this one) is to dynamically create the above layout at runtime in the
    ItemDataBound event for the parent DataGrid. I am trying to do this with a
    PlaceHolder control. At runtime I create the table, rows, cells,
    radiobuttons and labels like this:

    public void LoadChildRecords(object Sender, DataGridItemEventArgs e){
    if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType ==
    DataView dvOptions =
    //the datasource for the datagrid is a dataset w/ 2 tables and one relation
    named "ProductOptions"

    System.Web.UI.HtmlControls.HtmlTable tbl = new HtmlTable();
    tbl.Border = 0;
    tbl.CellPadding = 0;
    tbl.CellSpacing = 0;
    tbl.Width = "100%";
    for(int i=0; i<dvOptions.Count; i++){
    HtmlTableRow tr = new HtmlTableRow();
    HtmlTableCell td = new HtmlTableCell();
    HtmlInputRadioButton rad = new HtmlInputRadioButton();
    rad.ID = "radFinish";
    rad.Name = "radFinish";
    rad.Value = dvOptions["ProductSKU"].ToString();
    rad.EnableViewState = true;
    Label lblFinish = new Label();
    lblFinish.Text = dvOptions["FinishDescription"].ToString();
    rad.Checked = true;
    HtmlTableCell td2 = new HtmlTableCell();
    Label lbl = new Label();
    lbl.Text =
    phdPrintFinish = (PlaceHolder)e.Item.FindControl("phdPrintFinish");


    However, those controls are not there at postback. I have read that I must
    create them during the Page_OnInit event, but what I don't get is how I
    could do that when I don't know how many controls need to be created until I
    have the data. Can I create and bind the Datagrid and create the controls
    all during the Page_OnInit event? I have considered creating a Server
    Control which inherits from RadioButton list and overriding the render
    method, but I'm still a bit green in a lot of areas and I don't quite know
    where to start if I were to do that.

    So is there a more efficient (or simple) way to accomplish this?

    Mark Miller, Jul 30, 2003
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.