Results 1 to 6 of 6

Thread: [2005] Checkbox/radiobuttonlist next to childs in master/child data

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    Belgium
    Posts
    68

    [2005] Checkbox/radiobuttonlist next to childs in master/child data

    Hi,

    I've got some master/child data and I want to display a checkbox or radiobutton next to each child, depending on a value the master has.

    The checkboxes or radiobuttons should also be grouped for each master record. (each master record would have a list of controls, one control next to each of his children).

    I am currently displaying the data (without checkbox/radiobuttons) using a nested repeater, but I'm at a loss on how to manage the checkbox/radiobuttons.

    I already tried manually putting either a checkboxlist of radiobutton list in ascx file, but I noticed I couldn't put the list above the repeater and dynamically add a listitem for each row.

    Any pointers would be welcome.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Checkbox/radiobuttonlist next to childs in master/child data

    Show your ItemTemplate.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    Belgium
    Posts
    68

    Re: [2005] Checkbox/radiobuttonlist next to childs in master/child data

    Code:
        <asp:Repeater ID="question" runat="server" OnItemDataBound="question_ItemDataBound">
            <ItemTemplate>
                <tr>
                    <td >
                        <%# DataBinder.Eval(Container.DataItem, "Description") %></br>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <table border="0">
                            <asp:Repeater ID="answer" runat="server">
                                <ItemTemplate>
                                    <tr>                             
                                        <td>                 
                                            <%# DataBinder.Eval(Container.DataItem, "Description") %>
                                            </br>
                                        </td>
                                        <td>
                                            <asp:RadioButton ID="RadioButton1" runat="server" />
                                        </td>        
                                    </tr>
                                </ItemTemplate>
                            </asp:Repeater>
                        </table>
                        <br />
                    </td>
                </tr>
            </ItemTemplate>
        </asp:Repeater>
    (Both question and answer tables have a description field)

    VB Code:
    1. protected void question_ItemDataBound(object sender, RepeaterItemEventArgs e)
    2.     {
    3.         RepeaterItem item = e.Item;
    4.         if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem))
    5.         {
    6.             Repeater Answer = (Repeater)item.FindControl("answer");
    7.             DataRowView drv = (DataRowView)item.DataItem;
    8.             Answer.DataSource = drv.CreateChildView("Question_Answer");
    9.             Answer.DataBind();
    10.         }
    11.     }

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Checkbox/radiobuttonlist next to childs in master/child data

    So shouldn't you just place the master radiobuttons like here:

    Code:
        <asp:Repeater ID="question" runat="server" OnItemDataBound="question_ItemDataBound">
            <ItemTemplate>
                <tr>
                    <td >
                        <%# DataBinder.Eval(Container.DataItem, "Description") %></br>
                        <asp:Radiobutton............................ />
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <table border="0">
                            <asp:Repeater ID="answer" runat="server">
                                <ItemTemplate>
                                    <tr>                             
                                        <td>                 
                                            <%# DataBinder.Eval(Container.DataItem, "Description") %>
                                            </br>
                                        </td>
                                        <td>
                                            <asp:RadioButton ID="RadioButton1" runat="server" />
                                        </td>        
                                    </tr>
                                </ItemTemplate>
                            </asp:Repeater>
                        </table>
                        <br />
                    </td>
                </tr>
            </ItemTemplate>
        </asp:Repeater>

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    Belgium
    Posts
    68

    Re: [2005] Checkbox/radiobuttonlist next to childs in master/child data

    That would show 1 radiobutton for each question. I need one for each answer in each question, grouped by question.

    I found out I could manually assign them a group, for instance the questionID. However, that created a problem since ASP renames all the controls when generating the html so they 'wouldn't' end up in the same group after all.

    A workaround would be to use a custom radiobutton control that overrides some functionality regarding the name change.

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Checkbox/radiobuttonlist next to childs in master/child data

    Ah, now I see what you mean. Yes, ASP.NET does rename these controls and you do end up with independent radio buttons.

    How about using a RadioButtonList which, in the ItemDataBound event, you bind to a dataset containing specific answers?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width