如何将TreeView树形控件的CheckBox复选框更换为radio单选按钮?

    文章来源:万象互联 更新时间:2013-8-1 13:53:20
分享:

客户网站需要显示部门及员工列表,这个用ASP.net中的TreeView树形列表控件再合适不过了。但是因操作需要,客户需要每个客户名字前面的复选框换成单选按钮。如何做到呢?下面的代码可以轻松搞定。

前台页面代码:

<asp:TreeView runat="server" ID="tvAi" Font-Bold="true" ShowLines="true" EnableClientScript="true"

ShowExpandCollapse="true" ShowCheckBoxes="All"

SelectedNodeStyle-ForeColor="Azure" >

</asp:TreeView>

后台数据绑定代码:

private void BindTreeview()

{

var pk = this.GetTreeViewNodes(); // this is simply to get the records to bind into the GridView

tvAi.Nodes.Clear();

int redindex = 1;

foreach (var parentNode in pk)

{

TreeNode master = new TreeNode(parentNode.Value.ToString(), parentNode.Key.ToString());

master.ShowCheckBox = false;

tvAi.Nodes.Add(master);

var sk = this.GetSubnodesOfTheParentNodes(parentNode.Key);

foreach (var chileNode in sk)

{

TreeNode child = new TreeNode(chileNode.Value.ToString(), chileNode.Key.ToString());

child.ShowCheckBox = false;

child.Text = "<input type=radio name=rdoC" + redindex.ToString() + " value ="+chileNode.Value.ToString()+" />" + child.Text;

master.ChildNodes.Add(child);

}

redindex++;

}

}

最终效果图:

版权说明:本站原创文章,由万象互联SEO优化发表.
本文地址:https://www.hulian.top/zixun/post/5924.html
在线咨询
  • 在线时间
  • 8:00-21:00