ASP.NET Custom Treeview with custom TreeNode
I have a question regarding the ASP.NET 3.5 Treeview and Treenodes. I'd like to build a Treeivew that supports multistate checkbox. 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). 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. I am showing static data in an .xml file, and I really like the capability of binding the treeview to a datasource. So, I'd prefer to continue using the tree if I can.
So I guess I have a few questions:
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? Or can I add .cs files to my project?
Does anyone have any ideas on how to change the treeNode to handle checkstates?
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? Or can I add .cs files to my project?
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:
namespace MyWebsiteControls
{
...
}
Then, include a reference to that namespace int the web.config file under:
<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:
<MyWebsiteControls:XTreeView ID="TreeView1" runat="server" DataSourceID="Checklist"
ShowCheckBoxes="All" CssClass="treeViewStyle">
</MyWebsiteControls:XTreeView>
精彩评论