这不就是个TreeView?我要的是 TreeView 后面的日期,是表格控制的吗怎么对齐的?
@happydaily: 后面有多列啊。
// create a TreeNode from the specified path, text and type private TreeViewSample Node( string path, string text, string type ) { TreeNode n = new TreeNode(); n.Type = type; StringBuilder nodeText = new StringBuilder(); if ( type == "file" ) { _idNumber++; nodeText.Append(@"<table border=""0"" cellpadding=""0"" cellspacing=""0""><tr><td width=""100px"">") ; nodeText.Append(@"<b><a style=""text-decoration:none;cursor:default;background:white;color:black;font-size:16;font-weight:bold"" href=""javascript:void(0)"""); nodeText.Append(@"> ").Append(text.Trim()).Append("</a></b>"); nodeText.Append(@"</td><td width=""150px"">"); nodeText.Append(@"<b><a style=""background:white;color:red;font-size:16;font-weight:bold"" href=""<a href="%22http://www.google.com/%22">http://www.google.com/</a>"""); nodeText.Append(@">www.google.com </a></b>"); nodeText.Append(@"</td><td width=""100px"">"); nodeText.Append(@"<INPUT id=""").Append(_idNumber.ToString()).Append(@""" type=""button"" onclick=""javascript:clickedMe()"" value=""Click Me!"">"); nodeText.Append(@"</td></tr></table>"); } else if ( type == "folder" ) { nodeText.Append(@"<table border=""0"" cellpadding=""0"" cellspacing=""0""><tr><td width=""100px"">") ; nodeText.Append(@"<b><a style=""text-decoration:none;cursor:default;background:white;color:black;font-size:16;font-weight:bold"" href=""javascript:void(0)"""); nodeText.Append(@"> ").Append(text.Trim()).Append("</a></b>"); nodeText.Append(@"</td></tr></table>"); } n.Text = nodeText.ToString(); return n; }
@happydaily:
前台代码:
<%@ Page Language="c#" Inherits="Telerik.TreeListExamplesCSharp.FirstLook.DefaultCS" CodeFile="DefaultCS.aspx.cs" %> <%@ Register TagPrefix="telerik" Namespace="Telerik.QuickStart" %> <%@ Register TagPrefix="telerik" TagName="Header" Src="~/Common/Header.ascx" %> <%@ Register TagPrefix="telerik" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %> <%@ Register TagPrefix="telerik" TagName="Footer" Src="~/Common/Footer.ascx" %> <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/tr/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <telerik:HeadTag runat="server" ID="Headtag2" /> </head> <body class="BODY"> <form runat="server" id="mainForm" method="post"> <telerik:Header runat="server" ID="Header1" NavigationLanguage="CS" /> <!-- content start --> <telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="RadTreeList1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadTreeList1" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="CheckBox1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadTreeList1" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="CheckBox2"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadTreeList1" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="DropDownList1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadTreeList1" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="CheckBox3"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadTreeList1" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="CheckBox4"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadTreeList1" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="CheckBox5"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadTreeList1" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="CheckBox6"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadTreeList1" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"> </telerik:RadAjaxLoadingPanel> <qsf:ConfiguratorPanel runat="server" ID="ConfigurationPanel1" Title="Configure RadTreeList" Expanded="true"> <table> <tr> <td style="width: 270px"> <asp:CheckBox ID="CheckBox1" runat="server" Text="Show outer borders" Checked="true" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged" /><br /> <asp:CheckBox ID="CheckBox2" runat="server" Text="Show tree lines" Checked="true" AutoPostBack="true" OnCheckedChanged="CheckBox2_CheckedChanged" /><br /> Change treelist lines: <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"> <asp:ListItem Selected="True">Both</asp:ListItem> <asp:ListItem>Horizontal</asp:ListItem> <asp:ListItem>None</asp:ListItem> <asp:ListItem>Vertical</asp:ListItem> </asp:DropDownList> </td> <td style="width: 270px;" valign="top"> <asp:CheckBox ID="CheckBox3" runat="server" Text="Enable paging" Checked="true" AutoPostBack="true" OnCheckedChanged="CheckBox3_CheckedChanged" /><br /> <asp:CheckBox ID="CheckBox4" runat="server" Text="Enable sorting" Checked="true" AutoPostBack="true" OnCheckedChanged="CheckBox4_CheckedChanged" /> </td> <td valign="top"> <asp:CheckBox ID="CheckBox5" runat="server" Text="Enable client-side items selection" Checked="false" AutoPostBack="true" OnCheckedChanged="CheckBox5_CheckedChanged" /><br /> <asp:CheckBox ID="CheckBox6" runat="server" Text="Allow multi-item selection" Checked="false" AutoPostBack="true" OnCheckedChanged="CheckBox6_CheckedChanged" /> </td> </tr> </table> </qsf:ConfiguratorPanel> <telerik:RadTreeList ID="RadTreeList1" runat="server" OnNeedDataSource="RadTreeList1_NeedDataSource" ParentDataKeyNames="ParentID" DataKeyNames="ID" AllowPaging="true" PageSize="5" AutoGenerateColumns="false" AllowSorting="true"> <Columns> <telerik:TreeListBoundColumn DataField="ID" UniqueName="ID" HeaderText="Category ID" /> <telerik:TreeListTemplateColumn DataField="ProductName" UniqueName="ProductName" HeaderText="Product"> <ItemTemplate> <%# Eval("ProductName")%><%# Eval("Quantity").ToString() != "" ? " (" + Eval("Quantity").ToString() + ")" : ""%> </ItemTemplate> <HeaderStyle Width="300px" /> </telerik:TreeListTemplateColumn> <telerik:TreeListBoundColumn DataField="Price" UniqueName="Price" DataFormatString="{0:C2}" HeaderText="Price" DataType="System.Decimal"> <ItemStyle HorizontalAlign="Right" /> </telerik:TreeListBoundColumn> <telerik:TreeListCheckBoxColumn DataField="InStock" UniqueName="InStock" HeaderText="In stock"> <HeaderStyle Width="60px" /> <ItemStyle HorizontalAlign="Center" /> </telerik:TreeListCheckBoxColumn> <telerik:TreeListBoundColumn DataField="ParentID" UniqueName="ParentID" HeaderText="Parent Category ID" /> </Columns> </telerik:RadTreeList> <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" /> <!-- content end --> <telerik:Footer runat="server" ID="Footer1"></telerik:Footer> </form> </body> </html>
后台代码:
using System; using System.Configuration; using System.Data; using System.Data.SqlClient; using Telerik.Web.UI; using System.Collections.Generic; using System.Web.UI.WebControls; namespace Telerik.TreeListExamplesCSharp.FirstLook { public partial class DefaultCS : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { RadTreeList1.ExpandedIndexes.Add(new TreeListHierarchyIndex { LevelIndex = 0, NestedLevel = 0 }); RadTreeList1.ExpandedIndexes.Add(new TreeListHierarchyIndex { LevelIndex = 1, NestedLevel = 0 }); RadTreeList1.ExpandedIndexes.Add(new TreeListHierarchyIndex { LevelIndex = 2, NestedLevel = 0 }); } } protected void RadTreeList1_NeedDataSource(object sender, TreeListNeedDataSourceEventArgs e) { RadTreeList1.DataSource = MyData.GetData(); } protected void CheckBox1_CheckedChanged(object sender, EventArgs e) { RadTreeList1.ShowOuterBorders = CheckBox1.Checked; } protected void CheckBox2_CheckedChanged(object sender, EventArgs e) { RadTreeList1.ShowTreeLines = CheckBox2.Checked; } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { switch (DropDownList1.SelectedValue) { case "Both": RadTreeList1.GridLines = TreeListGridLines.Both; break; case "Horizontal": RadTreeList1.GridLines = TreeListGridLines.Horizontal; break; case "None": RadTreeList1.GridLines = TreeListGridLines.None; break; case "Vertical": RadTreeList1.GridLines = TreeListGridLines.Vertical; break; } } protected void CheckBox3_CheckedChanged(object sender, EventArgs e) { RadTreeList1.AllowPaging = CheckBox3.Checked; RadTreeList1.Rebind(); } protected void CheckBox4_CheckedChanged(object sender, EventArgs e) { RadTreeList1.AllowSorting = CheckBox4.Checked; RadTreeList1.SortExpressions.Clear(); RadTreeList1.Rebind(); } protected void CheckBox5_CheckedChanged(object sender, EventArgs e) { RadTreeList1.ClientSettings.Selecting.AllowItemSelection = CheckBox5.Checked; RadTreeList1.ClearSelectedItems(); } protected void CheckBox6_CheckedChanged(object sender, EventArgs e) { RadTreeList1.AllowMultiItemSelection = CheckBox6.Checked; } } public class MyData { public static List<MyItem> GetData() { List<MyItem> list = new List<MyItem>(); list.Add(new MyItem("A", "Appetizers", "", null, true, "")); list.Add(new MyItem("B", "Beverages", "", null, true, "")); list.Add(new MyItem("C", "Cheese", "", null, false, "")); list.Add(new MyItem("A1", "Southwestern Twisted Chips", "150 gr.", 6.79m, false, "A")); list.Add(new MyItem("A2", "Top Shelf Combo Appetizer", "300 gr.", 9.49m, true, "A")); list.Add(new MyItem("B1", "Sangria", "90 ml.", 6.49m, true, "B")); list.Add(new MyItem("B2", "Margarita", "60 ml.", 7.39m, false, "B")); list.Add(new MyItem("B3", "Red Cherry Boost", "200 ml.", 6.99m, false, "B")); list.Add(new MyItem("B4", "Mojito", "180 ml.", 7.59m, true, "B")); list.Add(new MyItem("C1", "Blue Cheese and Hazelnut Shortbread", "220 gr.", 10.69m, false, "C")); list.Add(new MyItem("C2", "Avocado Feta Salsa", "240 gr.", 7.19m, false, "C")); return list; } } public class MyItem { public string ID { get; set; } public string ProductName { get; set; } public string Quantity { get; set; } public decimal? Price { get; set; } public bool InStock { get; set; } public string ParentID { get; set; } public MyItem(string id, string productName, string quantity, decimal? price, bool inStock, string parentID) { ID = id; ProductName = productName; Quantity = quantity; Price = price; InStock = inStock; ParentID = parentID; } } }
楼上给的地址挺好,学习了。。。