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

[Solved] Can checkbox be databound?

4 Answers 170 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Nancy Cara
Top achievements
Rank 1
Nancy Cara asked on 13 Mar 2008, 03:09 AM
I'd like the checkbox field to databind to my IsChecked field in my sqldatasource. Is this possible or do I have to check it OnNodeDataBound in code behind?

4 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 13 Mar 2008, 09:37 AM
Hi Nancy Cara,

You have to wire the NodeDataBound event and set the Checked property of the TreeNodes in its event handler. Please refer to the following article:

The NodeDataBound event

Hope this helps.

Sincerely yours,
Nick
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Nancy Cara
Top achievements
Rank 1
answered on 13 Mar 2008, 03:55 PM
Okay. I'm passing in my IsChecked value in the sqldatasource but see no way to access it in the NodeDataBound event. I have ID, ParentID, Text = Name, and Value = RowID. I see no other place to store a second value for IsChecked. I sure don't want to have to go out and call the database on each node for checked when it's already being passed in with the data. How would I do this.

Database is set up for self-referencing hierarchy:

ID
Name   --->  Text
ParentID
RowID --->  Value
Is Checked   --> ??  How do I access this on node data bound?
0
Accepted
Veselin Vasilev
Telerik team
answered on 13 Mar 2008, 04:19 PM
Hi Nancy Cara,

I guess your SQL query is something similar to this:

select Id, Name, RowId, IsChecked from table

Now, in NodeDataBound event handler you can access the database value for the particular node by 

... = (e.Node.DataItem as DataRowView)["IsChecked"].ToString(); 
 
as shown in the help article. It does not perform a new query to the database.

Greetings,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Nancy Cara
Top achievements
Rank 1
answered on 13 Mar 2008, 04:51 PM
Fantastic! Thank-you Veskoni. You guys are great!
Tags
TreeView
Asked by
Nancy Cara
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Nancy Cara
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or