Is a Databound RadButton inside a DataList Possible?

2 posts, 0 answers
  1. Steve
    Steve avatar
    84 posts
    Member since:
    Aug 2013

    Posted 11 Nov 2013 Link to this post

    Is it possible to put a RadButton inside a bound DataList?



    I have a dataset with two columns returned (bound in the code-behind). First column is called HowFoundDesc (a description), and second is FoundThisWay (a Boolean). I can bind the HowFoundDesc to the Text attribute of the DataList, but I don't know how to bind the FoundThisWay Boolean flag to the RadButton so as to toggle the state of the button (it is a toggle radio button with images).

    When I run it, I get the descriptions fine for each, but all the images are defaulting to the off value. Also, when I click on the buttons, they are all acting separate instead of a group, even though I have the groupname defined in the RadButton.



    Any ideas?





    <div Style="font-size: 14px; top: 4px; left: 5px; position: absolute;">
     <asp:DataList ID="HowFound" runat="server" RepeatDirection="Horizontal" RepeatColumns="5"  >
         <ItemTemplate>
             <telerik:RadButton ID="rbHowFound" runat="server" ForeColor="Blue" AutoPostBack="false" ButtonType="ToggleButton" GroupName="grpHowFound"
                 ToggleType="Radio" Text=<%# Eval("HowFoundDesc")%>  >
                 <ToggleStates>
                     <telerik:RadButtonToggleState PrimaryIconCssClass="rbRemove" />
                     <telerik:RadButtonToggleState PrimaryIconCssClass="rbOk" Selected="true" />
                 </ToggleStates>
             </telerik:RadButton>
         </ItemTemplate>
     </asp:DataList>
     </div>








  2. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1490 posts

    Posted 14 Nov 2013 Link to this post

    Hello Steve,

    The GroupName of the RadButtons is different for each instance of the ItemTemplate of the databound control. This behavior is expected and can be observed with other controls like ASP Radiobutton.

    What I can suggest you is try the following:
    • Instead of putting the RadButton into an ItemTemplate of a databound control, you can iterate through the values of a particular field from the datasource. Then you and create a RadButton with the desired configuration, on each iteration.
    • OR you can keep up with the current approach and use the following workaround:
    <script type="text/javascript">
      
       Telerik.Web.UI.RadButton.prototype.get_uniqueGroupName = function () {
       return this.get_groupName();
    }
    </script>
    In order the workaround to take effect it should be put at the end of your page.

    Regards,
    Danail Vasilev
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top