FineUI 官方论坛
标题:
<f:Tree>控件绑定列表项后点击某一项仍会在增加相应列表项
[打印本页]
作者:
zhangdaxu
时间:
2017-5-22 10:16
标题:
<f:Tree>控件绑定列表项后点击某一项仍会在增加相应列表项
本帖最后由 zhangdaxu 于 2017-5-22 10:26 编辑
Equipment.Master:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Equipment.master.cs"
Inherits="SinoPriceMonitor.SubPage.Equipment.Equipment" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style>
.x-grid-row-summary .x-grid-cell-inner
{
font-weight: bold;
color: red;
}
</style>
<asp:ContentPlaceHolder ID="headCPH" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<f:PageManager ID="PageManager1" AutoSizePanelID="Panel1" runat="server" />
<f:Panel ID="Panel1" runat="server" ShowBorder="true" ShowHeader="false" Title="母版页"
Layout="HBox" BoxConfigAlign="Stretch" BoxConfigPosition="Start" BoxConfigChildMargin="0 5 0 0"
BodyPadding="5">
<Items>
<f:Tree ID="Tree1" Width="200px" EnableCollapse="true" ShowHeader="true" Title="选择省份" OnNodeCommand="Tree1_NodeCommand" runat="server" >
<Listeners>
<f:Listener Event="beforeitemcontextmenu" Handler="onTreeNodeContextMenu" />
</Listeners>
</f:Tree>
<f:Menu ID="Menu1" runat="server">
<Items>
<f:MenuButton ID="btnExpandNode" EnablePostBack="false" runat="server" Text="展开全部">
<Listeners>
<f:Listener Event="click" Handler="onExpandNode" />
</Listeners>
</f:MenuButton>
<f:MenuButton ID="btnCollapseNode" EnablePostBack="false" runat="server" Text="折叠全部">
<Listeners>
<f:Listener Event="click" Handler="onCollapseNode" />
</Listeners>
</f:MenuButton>
</Items>
<Listeners>
<f:Listener Event="show" Handler="onMenuShow" />
</Listeners>
</f:Menu>
<f:CPHConnector ID="CPHConnector1" runat="server">
<asp:ContentPlaceHolder ID="mainCPH" runat="server">
</asp:ContentPlaceHolder>
</f:CPHConnector>
</Items>
</f:Panel>
</form>
<script src="../../js/jquery-1.11.1.min.js" type="text/javascript"></script>
<script>
var treeID = '<%= Tree1.ClientID %>';
var menuID = '<%= Menu1.ClientID %>';
// 保存当前菜单对应的树节点ID
var currentNodeId;
// 返回false,来阻止浏览器右键菜单
function onTreeNodeContextMenu(view, record, item, index, event) {
currentNodeId = record.getId();
F(menuID).showAt(event.getXY());
event.stopEvent();
}
// 设置所有菜单项的禁用状态
function setMenuItemsDisabled(disabled) {
var menu = F(menuID);
$.each(menu.items.items, function (index, item) {
disabled ? item.disable() : item.enable();
});
}
// 显示菜单后,检查是否禁用菜单项
function onMenuShow() {
if (currentNodeId) {
var tree = F(treeID);
var store = tree.getStore();
var nodeData = store.getById(currentNodeId);
if (nodeData.data.leaf) {
setMenuItemsDisabled(true);
} else {
setMenuItemsDisabled(false);
}
}
}
function onExpandNode() {
if (currentNodeId) {
var tree = F(treeID);
var store = tree.getStore();
tree.expandNode(store.getById(currentNodeId), true);
}
}
function onCollapseNode() {
if (currentNodeId) {
var tree = F(treeID);
var store = tree.getStore();
tree.collapseNode(store.getById(currentNodeId), true);
}
}
</script>
</body>
</html>
复制代码
Equipment.Master.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;
using System.Data;
using SinoPriceMonitor.DAL;
namespace SinoPriceMonitor.SubPage.Equipment
{
public partial class Equipment : System.Web.UI.MasterPage
{
public delegate void ProcessLeftTreeNodeClickDelegate(string treeNodeId, string treeNodeText);
public ProcessLeftTreeNodeClickDelegate ProcessLeftTreeNodeClick
{
get;
set;
}
protected void Page_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
//// 模拟从数据库返回数据表
DataTable table = Sys_Equipment.SP_Province_GetList();
foreach (DataRow row in table.Rows)
{
FineUI.TreeNode node = new FineUI.TreeNode();
node.Text = row["Province_Name"].ToString();
node.NodeID = row["Province_Code"].ToString();
Tree1.Nodes.Add(node);
DataTable table2 = Sys_Equipment.A_MainMarket_Company_GetList(Convert.ToInt32(row["Province_Code"].ToString()));
foreach (DataRow row2 in table2.Rows)
{
FineUI.TreeNode node2 = new FineUI.TreeNode();
node2.Text = row2["Company"].ToString();
node2.EnableClickEvent = true;
node.Nodes.Add(node2);
}
}
}
protected void Tree1_NodeCommand(object sender, TreeCommandEventArgs e)
{
if (ProcessLeftTreeNodeClick != null)
{
ProcessLeftTreeNodeClick(e.NodeID, e.Node.Text);
}
}
}
}
复制代码
作者:
sanshi
时间:
2017-5-22 13:29
protected void Page_Load(object sender, EventArgs e)
{
LoadData();
}
复制代码
一般来说,Page_Load 中的代码应该放到 !IsPostBack 中,类似:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Calendar1.MinDate = DateTime.Now;
Calendar1.MaxDate = DateTime.Now.AddDays(20);
Calendar1.SelectedDate = DateTime.Now.AddDays(10);
Button1.Text = String.Format("选中{0}", DateTime.Now.AddDays(2).ToString(Calendar1.DateFormatString));
}
}
复制代码
作者:
zhangdaxu
时间:
2017-5-24 11:01
晕
,真是迷糊了,就是这个原因,感谢大神赐教
欢迎光临 FineUI 官方论坛 (https://fineui.com/BBS/)
Powered by Discuz! X3.4