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

FormTemplate: checkbox (boolean) DataBinding

1 Answer 77 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Lukasz Kalbarczyk
Top achievements
Rank 1
Lukasz Kalbarczyk asked on 15 Jan 2012, 05:21 PM
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?

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 18 Jan 2012, 10:13 AM
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
Tags
TreeList
Asked by
Lukasz Kalbarczyk
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or