Databinding slider in Grid

3 posts, 1 answers
  1. Stephen
    Stephen avatar
    8 posts
    Member since:
    Feb 2011

    Posted 21 Sep 2011 Link to this post

    I'm having quite the issue trying to DataBind a bool? value to the Enabled property slider in a GridTemplateColumn of a Grid.
    Here is my setup:
    <telerik:RadGrid ID="_rgPermissions" runat="server" AutoGenerateColumns="False" HeaderStyle-Font-Bold="true"
                        AllowSorting="true" GridLines="None" Width="517px" Height="595px" Skin="Office2007"
                        OnNeedDataSource="_rgPermissions_NeedDataSource" OnItemDataBound="_rgPermissions_ItemDataBound"
                        <AlternatingItemStyle BackColor="#f4f5f7" />
                        <GroupingSettings CaseSensitive="false" />
                                <telerik:GridBoundColumn UniqueName="roleName" ItemStyle-Font-Size="X-Small" DataField="roleName"
                                <telerik:GridTemplateColumn UniqueName="SliderPermissions" HeaderText="Permissions"
                                    ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="300px">
                                        <telerik:RadSlider runat="server" ID="_slPermissions" Orientation="Horizontal" Width="325px"
                                            Height="40" TrackPosition="Center" ItemType="Item" Skin="Windows7"
                                            OnClientBeforeValueChange="IsItemDisabledOnPermissionsSlider" >
                                                <telerik:RadSliderItem Text="None" Value="None" ToolTip="No permissions" runat="server">
                                                <telerik:RadSliderItem Text="View" Value="View" Enabled='<%# Convert.ToString(DataBinder.Eval(Container, "DataItem.View_Static")).Equals("") ? true : !(bool)DataBinder.Eval(Container, "DataItem.View_Static") %>'
                                                    ToolTip="Role can view folder and its contents" runat="server"></telerik:RadSliderItem>
                                                <telerik:RadSliderItem Text="Add" Value="Add" Enabled='<%# Convert.ToString(DataBinder.Eval(Container, "DataItem.Add_Static")).Equals("") ? true : !(bool)DataBinder.Eval(Container, "DataItem.Add_Static") %>'
                                                    ToolTip="Role can upload files to folder or create new folders within" runat="server">
                                                <telerik:RadSliderItem Text="Edit" Value="Edit" Enabled='<%# Convert.ToString(DataBinder.Eval(Container, "DataItem.Edit_Static")).Equals("") ? true : !(bool)DataBinder.Eval(Container, "DataItem.Edit_Static") %>'
                                                    ToolTip="Role can edit folder and its contents" runat="server"></telerik:RadSliderItem>
                                                <telerik:RadSliderItem Text='Delete' Value="Delete" Enabled='<%# Convert.ToString(DataBinder.Eval(Container, "DataItem.Delete_Static")).Equals("") ? true : !(bool)DataBinder.Eval(Container, "DataItem.Delete_Static") %>'
                                                    ToolTip="Role can delete folder and its contents" runat="server"></telerik:RadSliderItem>
                                <telerik:GridBoundColumn DataField="View_Static" Visible="false" UniqueName="View_Static">
                                <telerik:GridBoundColumn DataField="Add_Static" Visible="false" UniqueName="Add_Static">
                                <telerik:GridBoundColumn DataField="Edit_Static" Visible="false" UniqueName="Edit_Static">
                                <telerik:GridBoundColumn DataField="Delete_Static" Visible="false" UniqueName="Delete_Static">
                                <telerik:GridBoundColumn UniqueName="roleID" Visible="false" DataField="roleID" AllowSorting="true">
                                <telerik:GridBoundColumn UniqueName="parentMasterID" DataField="parentMasterID" Visible="false"
                                <telerik:GridBoundColumn DataField="FolderPermissionsID" Visible="false" UniqueName="FolderPermissionsID">
                        <HeaderStyle BorderColor="DarkGray" BorderStyle="Solid" BorderWidth="1px" />
    <telerik:RadCodeBlock ID="_rcb" runat="server">
        <script type="text/javascript">
          function IsItemDisabledOnPermissionsSlider(sender, args) {
                if (!sender.get_items()[args.get_newValue()].get_enabled())

    This is not working at all. Every item in the slider still remains enabled. Note, while the "Static" bool's can be null, I tried this is with a bool value guaranteed not to be null using Enabled='<%# !(bool)DataBinder.Eval(Container, "DataItem.NormalBool") %>' , and it still doesn't work.
    I even tried to do Text='<%# DataBinder.Eval(Container, "DataItem.SomeText") %>' and that didn't show up. Nothing seems to DataBind to the Sliders.

    Any advice?
    I know I can do all of this through the Grid's itemdatabound, but I'd prefer not to.
  2. Answer
    Niko avatar
    404 posts

    Posted 27 Sep 2011 Link to this post

    Hi Stephen,

    Unfortunately you cannot achieve the desired effect with this approach. Keep in mind that the RadSlider control itself is data-bindable. Being so you cannot simply use the same data container for the RadSlider as it is not a static part of the Template of the Grid. Moreover the slider itself tries to do a data binding, but it is missing the necessary data as it does not have its own DataSource.
    Therefore you have to make a choice for the approach you will go with.
    On one hand you can use the ItemDataBound event of the RadGrid, as you have mentioned.
    On the other you can assign a DataSource to the RadSlider and rely on its OnDataBound event. Using the latter approach you will escape the search for the slider in the Grid's item and you will still have the DataSource assigned to the slider control.

      At the end of the day, either approach is equally valid and reasonable. Which of them you will choose is only a matter of preference.

    Hope this helps.

    All the best,
    the Telerik team
    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 their blog feed now
  3. Stephen
    Stephen avatar
    8 posts
    Member since:
    Feb 2011

    Posted 18 Jan 2012 Link to this post

    Doh! I should have realized that about the data-binding.  Thank you for your response!
Back to Top