FormTemplate: checkbox (boolean) DataBinding

2 posts, 0 answers
  1. Lukasz Kalbarczyk
    Lukasz Kalbarczyk avatar
    24 posts
    Member since:
    Feb 2010

    Posted 15 Jan 2012 Link to this post

    Inside my FormTemplate I have:

    <asp:CheckBox ID="WidocznaCheckBox" runat="server" Text="Pokazuj w drzewie" CssClass="cbx" Checked='<%#Bind("Widoczna") %>'></asp:CheckBox>

    But when I'm trying to add a new record to the RadTreeList, "Specified Cast Is not Valid" is thrown.

    Using RadGrid It was possibile to write a small code-snippet:

    if ((e.CommandName == RadGrid.InitInsertCommandName))
    {
        e.Canceled = true;
        //Prepare an IDictionary with the predefined values 
        ListDictionary newValues = new ListDictionary();
     
        //set initial checked state for the checkbox on init insert 
        newValues["Widoczna"] = true
     
        //Insert the item and rebind 
        e.Item.OwnerTableView.InsertItem(newValues);
    }

    Is there for RatTreeList any similar or equivalent snippet?

    Or any other solution?
  2. Tsvetina
    Admin
    Tsvetina avatar
    1876 posts

    Posted 18 Jan 2012 Link to this post

    Hello Lukasz,

    You could try using the DefaultInsertValue property of the TreeListCheckBox column:
    <telerik:RadTreeList ID="RadTreeList1" runat="server" DataKeyNames="ID" ParentDataKeyNames="ParentID"
        OnNeedDataSource="RadTreeList1_NeedDataSource">
        <Columns>
            <telerik:TreeListEditCommandColumn>
            </telerik:TreeListEditCommandColumn>
            <telerik:TreeListCheckBoxColumn DefaultInsertValue="true" UniqueName="CheckBoxColumn"
                DataField="IsChecked">
            </telerik:TreeListCheckBoxColumn>
        </Columns>
        <EditFormSettings EditFormType="Template">
            <FormTemplate>
                <asp:CheckBox ID="chk" runat="server" Checked='<%#Bind("IsChecked") %>' />
            </FormTemplate>
        </EditFormSettings>
    </telerik:RadTreeList>

    With the above declaration, the RadTreeList control renders its form template without exceptions.

    Regards,
    Tsvetina
    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. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top