This is my default.aspx
And this is my code-behind.
When I dragged and dropped item treeview to textbox >>> It was fine. But when I dragged and dropped item treeview to radgrid >>> It didn't work . I had tested when I dragged and dropped into radgrid with a message alert >>> seem my "
<
form
id
=
"form1"
runat
=
"server"
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
>
</
telerik:RadScriptManager
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
GridLines
=
"None"
>
<
MasterTableView
>
<
CommandItemSettings
ExportToPdfText
=
"Export to Pdf"
/>
<
RowIndicatorColumn
>
<
HeaderStyle
Width
=
"20px"
/>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
>
<
HeaderStyle
Width
=
"20px"
/>
</
ExpandCollapseColumn
>
</
MasterTableView
>
</
telerik:RadGrid
>
<
telerik:RadTreeView
ID
=
"RadTreeView1"
Runat
=
"server"
CheckChildNodes
=
"True"
CheckBoxes
=
"True"
TriStateCheckBoxes
=
"False"
EnableDragAndDrop
=
"True"
EnableDragAndDropBetweenNodes
=
"True"
onnodedrop
=
"RadTreeView1_NodeDrop"
MultipleSelect
=
"true"
>
<
Nodes
>
<
telerik:RadTreeNode
runat
=
"server"
Text
=
"ThanhPho"
Checkable
=
"false"
AllowDrag
=
"False"
>
<
Nodes
>
<
telerik:RadTreeNode
runat
=
"server"
Text
=
"HCM"
Checkable
=
"False"
>
</
telerik:RadTreeNode
>
<
telerik:RadTreeNode
runat
=
"server"
Text
=
"HaNoi"
Checkable
=
"False"
>
</
telerik:RadTreeNode
>
<
telerik:RadTreeNode
runat
=
"server"
Text
=
"DaLat"
Checkable
=
"False"
>
<
Nodes
>
<
telerik:RadTreeNode
runat
=
"server"
Text
=
"Ho Xuân Hương"
Checkable
=
"true"
>
</
telerik:RadTreeNode
>
<
telerik:RadTreeNode
runat
=
"server"
Text
=
"Thung Lũng Tình Yêu"
Checkable
=
"true"
>
</
telerik:RadTreeNode
>
</
Nodes
>
</
telerik:RadTreeNode
>
</
Nodes
>
</
telerik:RadTreeNode
>
<
telerik:RadTreeNode
runat
=
"server"
Text
=
"Đất Nước"
Checkable
=
"false"
>
<
Nodes
>
<
telerik:RadTreeNode
runat
=
"server"
Text
=
"Việt Nam"
>
</
telerik:RadTreeNode
>
<
telerik:RadTreeNode
runat
=
"server"
Text
=
"Singapor"
>
</
telerik:RadTreeNode
>
<
telerik:RadTreeNode
runat
=
"server"
Text
=
"Japan"
>
</
telerik:RadTreeNode
>
</
Nodes
>
</
telerik:RadTreeNode
>
</
Nodes
>
</
telerik:RadTreeView
>
<
asp:Panel
ID
=
"Panel1"
runat
=
"server"
Height
=
"256px"
>
<
div
>
<
asp:TextBox
ID
=
"TextBox1"
runat
=
"server"
></
asp:TextBox
>
<
telerik:RadTextBox
ID
=
"RadTextBox1"
Runat
=
"server"
>
</
telerik:RadTextBox
>
<
br
/>
</
div
>
</
asp:Panel
>
<
telerik:RadAjaxManager
runat
=
"server"
ID
=
"RadAjaxManager1"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadTreeView1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadTreeView1"
UpdatePanelHeight
=
""
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"Panel1"
UpdatePanelHeight
=
""
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
UpdatePanelHeight
=
""
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
</
form
>
</
body
>
And this is my code-behind.
protected
void
Page_Load(
object
sender, EventArgs e)
{
PopulateGrid();
RadGrid1.Rebind();
}
protected
void
RadTreeView1_NodeDrop(
object
sender, Telerik.Web.UI.RadTreeNodeDragDropEventArgs e)
{
RadTreeNode sourceNode = e.SourceDragNode;
RadTreeNode DesNode = e.DestDragNode;
RadTreeViewDropPosition DropPosition = e.DropPosition;
if
(DesNode !=
null
)
{
if
(sourceNode.TreeView.SelectedNodes.Count <= 1)
{
PerformDragDrop(DropPosition, sourceNode, DesNode);
}
else
if
(sourceNode.TreeView.SelectedNodes.Count > 1)
{
foreach
(RadTreeNode node
in
sourceNode.TreeView.SelectedNodes)
{
PerformDragDrop(DropPosition, node, DesNode);
}
}
DesNode.Expanded =
true
;
sourceNode.TreeView.UnselectAllNodes();
}
else
if
(e.HtmlElementID ==
"TextBox1"
)
{
foreach
(RadTreeNode node
in
e.DraggedNodes)
{
TextBox1.Text = node.Text;
RadTextBox1.Text = node.Text;
}
//DataTable dt = (DataTable)Session["DaTatable"];
//foreach (RadTreeNode node in e.DraggedNodes)
//{
// string[] value = { node.Text, node.Value };
// dt.Rows.Add(value);
// RadGrid1.DataSource = dt;
// RadGrid1.DataBind();
// RadGrid1.Rebind();
//}
}
else
if
(e.HtmlElementID == RadGrid1.ClientID)
{
DataTable dt = (DataTable)Session[
"DaTatable"
];
foreach
(RadTreeNode node
in
e.DraggedNodes)
{
string
[] value = { node.Text, node.Value };
dt.Rows.Add(value);
RadGrid1.DataSource = dt;
RadGrid1.DataBind();
RadGrid1.Rebind();
}
}
}
private
static
void
PerformDragDrop(RadTreeViewDropPosition DropPosition, RadTreeNode sourceNode, RadTreeNode desNode)
{
switch
(DropPosition)
{
case
RadTreeViewDropPosition.Over:
// child
if
(!sourceNode.IsAncestorOf(desNode))
{
sourceNode.Owner.Nodes.Remove(sourceNode);
desNode.Nodes.Add(sourceNode);
}
break
;
case
RadTreeViewDropPosition.Above:
// sibling - above
sourceNode.Owner.Nodes.Remove(sourceNode);
desNode.InsertBefore(sourceNode);
break
;
case
RadTreeViewDropPosition.Below:
// sibling - below
sourceNode.Owner.Nodes.Remove(sourceNode);
desNode.InsertAfter(sourceNode);
break
;
}
}
private
void
PopulateGrid()
{
string
[] values = {
"One"
,
"Two"
};
DataTable dt =
new
DataTable();
dt.Columns.Add(
"Item"
);
dt.Columns.Add(
"Price"
);
//dt.Columns.Add("Category");
//dt.Rows[0]["Item"]=values[0];
//dt.Rows[0]["Price"] = values[1];
dt.Rows.Add(values);
dt.Rows.Add(values);
Session[
"DataTable"
] = dt;
RadGrid1.DataSource = dt;
RadGrid1.DataBind();
RadGrid1.Rebind();
}
(e.HtmlElementID == RadGrid1.ClientID)
" doesn't work because no message appeared. >>>> What 's wrong ???? Thanks a lot !!!