简体   繁体   English

具有自定义TreeNode的ASP.NET自定义Treeview

[英]ASP.NET Custom Treeview with custom TreeNode

I have a question regarding the ASP.NET 3.5 Treeview and Treenodes. 我对ASP.NET 3.5 Treeview和Treenodes有疑问。 I'd like to build a Treeivew that supports multistate checkbox. 我想构建一个支持多状态复选框的Treeivew。 I actually would like 4 states - checked, unchecked, indeterminate (like a tri-state box - parent is tri-state, if not all of the children are checked) and NotAppicable (this checkbox would be an X and greyed out). 我实际上想要4个状态-选中,未选中,不确定(如三态框-父级是三态,如果不是所有子项都选中的话)和NotAppicable(此复选框为X并显示为灰色)。 I've read up on how to add custom user controls, by using a Web User Control (.ascx), but it doesn't seem to work that way for overriding the TreeNode and TreeView. 我已经阅读了有关如何通过使用Web用户控件(.ascx)添加自定义用户控件的信息,但是对于覆盖TreeNode和TreeView而言,它似乎不起作用。 I am showing static data in an .xml file, and I really like the capability of binding the treeview to a datasource. 我在.xml文件中显示静态数据,并且我真的很喜欢将树视图绑定到数据源的功能。 So, I'd prefer to continue using the tree if I can. 因此,如果可以的话,我宁愿继续使用该树。

So I guess I have a few questions: 所以我想我有几个问题:

  1. How do I override the treeview or treenode, and add it to a webform? 如何覆盖treeview或treenode并将其添加到Webform? (So I can still use the designer?) Do I have to build them into a .dll and load that way? (因此,我仍然可以使用设计器吗?)是否必须将它们构建为.dll并以这种方式加载? Or can I add .cs files to my project? 还是可以将.cs文件添加到我的项目中?

  2. Does anyone have any ideas on how to change the treeNode to handle checkstates? 是否有人对如何更改treeNode以处理检查状态有任何想法?

  3. Any ideas on how to use my custom images for the different check states? 关于如何将自定义图像用于不同检查状态的任何想法?

Thanks! 谢谢!

I have an answer to my 1st question - How do I override the treeview or treenode, and add it to a webform? 我对第一个问题有一个答案-如何覆盖树视图或树节点,并将其添加到网络表单? (So I can still use the designer?) Do I have to build them into a .dll and load that way? (因此,我仍然可以使用设计器吗?)是否必须将它们构建为.dll并以这种方式加载? Or can I add .cs files to my project? 还是可以将.cs文件添加到我的项目中?

Everyone might know how to do this, but it was news to me. 每个人都可能知道该怎么做,但这对我来说是个新闻。 Add the extended classes to the App_Code folder in a namespace: 将扩展的类添加到名称空间中的App_Code文件夹中:

namespace MyWebsiteControls
{
   ...
}

Then, include a reference to that namespace int the web.config file under: 然后,在下面的web.config文件中包含对该名称空间的引用:

<pages/>
    <controls>
        <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add namespace="MyWebsiteControls" tagPrefix="MyWebsiteControls"/>
    </controls>
</pages>"

and then call your control in the .aspx file: 然后在.aspx文件中调用控件:

<MyWebsiteControls:XTreeView ID="TreeView1" runat="server" DataSourceID="Checklist"
    ShowCheckBoxes="All" CssClass="treeViewStyle">
</MyWebsiteControls:XTreeView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM