protected void RadTreeView1_NodeClick(object sender, RadTreeNodeEventArgs e)
{
if (e.Node.Level != 0)
{
// value of the selected child node
string text = e.Node.Value;
}
}
在这里我得到的文字值总是空的...请帮助我
在radtree节点单击事件中,我试图获取节点值
<telerik:RadTreeView ID="RadTreeView1" runat="server" Width="300px" Height="100px" Skin="Metro" OnNodeClick="RadTreeView1_NodeClick" AutoPostBack="true" OnClientNodeClicked="">
<DataBindings>
<telerik:RadTreeNodeBinding Expanded="True"></telerik:RadTreeNodeBinding>
</DataBindings>
</telerik:RadTreeView>
private void BindGrid()
{
try
{
DataView dv;
string json = class.HttpGet(url + "Services/Product.svc/ProductCategorySD1");
json = Regex.Unescape(json);
dt = (DataTable)JsonConvert.DeserializeObject(json.Trim(new Char[] { ' ', '"', '.' }), typeof(DataTable));
dv = dt.DefaultView;
grid.DataSource = dv;
grid.DataBind();
RadTreeView1.DataTextField = "ProductCategoryName";
RadTreeView1.DataFieldID = "ProductCategoryRowId";
RadTreeView1.DataFieldParentID = "ParentProductCategoryRowId";
RadTreeView1.DataSource = dt;
RadTreeView1.DataBind();
}
catch (Exception Err)
{
}
finally { }
}
treebinded完美..........................
答案 0 :(得分:0)
您必须明确设置DataValueField
和然后执行RadTreeView
操作的DataBind
属性:
RadTree1.DataTextField = "MyTextColumn"
// following line is absent from supplied sample in the OP
RadTree1.DataValueField = "MyValueColumn"
RadTree1.DataFieldID = "MyID"
RadTree1.DataFieldParentID = "MyParentID"
RadTree1.DataSource = ds
RadTree1.DataBind()
在OP中提供的示例代码中,您仅 设置DataTextField
。我的猜测是,如果你这样做:
string text = e.Node.Text;
您将成功阅读RadTreeNode
的文字。