This is a migrated thread and some comments may be shown as answers.

Is a Databound RadButton inside a DataList Possible?

1 Answer 17 Views
Button
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 12 Nov 2013, 02:41 AM

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>








1 Answer, 1 is accepted

Sort by
0
Danail Vasilev
Telerik team
answered on 14 Nov 2013, 01:22 PM
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.
Tags
Button
Asked by
Steve
Top achievements
Rank 1
Answers by
Danail Vasilev
Telerik team
Share this question
or