@小花要完整例子,尝试一下图文并茂,力求完整。
前台代码
- <ext:ResourceManager ID="ResourceManager1" DirectMethodNamespace="RM" runat="server" />
- <ext:Store ID="StoreDeptDetailList" OnBeforeStoreChanged="StoreChanged" runat="server">
- <Reader>
- <ext:JsonReader IDProperty="ID">
- <Fields>
- <ext:RecordField Name="ID" />
- <ext:RecordField Name="wzdm" />
- ... ....
- <ext:RecordField Name="bz" />
- </Fields>
- </ext:JsonReader>
- </Reader>
- </ext:Store>
- <ext:Viewport ID="Viewport1" runat="server" Layout="border">
- <Items>
- <ext:Panel ID="Panel1" runat="server" Region="West" Split="true" Width="225" Border="false"
- AutoScroll="true">
- <Content>
- <ext:TreePanel ID="treePanel" runat="server" Border="false">
- <Root>
- </Root>
- <Listeners>
- <Click Handler="e.stopEvent();RM.NodeClick(node.id);" />
- </Listeners>
- </ext:TreePanel>
- </Content>
- </ext:Panel>
- <ext:Panel ID="PanelCenter" runat="server" Region="Center" Layout="Fit" Cls="ViewPortRight"
- ButtonAlign="Right" Width="270" Header="false" Title="物资明细" Icon="TableGear"
- Border="false">
- <Items>
- <ext:GridPanel ID="gpFuncsList" runat="server" StripeRows="true" ClicksToEdit="0"
- Header="false" Height="600" StoreID="StoreDeptDetailList" Border="true" TrackMouseOver="true">
- <TopBar>
- <ext:Toolbar ID="Toolbar2" runat="server" AutoWidth="true">
- <Items>
- <ext:Label runat="server" ID="lblTitle">
- </ext:Label>
- <ext:ToolbarFill ID="ToolbarFill1" runat="server" />
- <ext:Button ID="btnAdd" runat="server" Text="新增" Icon="Add">
- <Listeners>
- <Click Handler="#{gpFuncsList}.insertRecord();" />
- </Listeners>
- </ext:Button>
- <ext:Button ID="btnDelete" runat="server" Text="删除" Icon="Delete">
- <Listeners>
- <Click Handler="#{gpFuncsList}.deleteSelected();" />
- </Listeners>
- </ext:Button>
- <ext:Button ID="btnSave" runat="server" Text="保存" Icon="Disk">
- <Listeners>
- <Click Handler="#{gpFuncsList}.save();" />
- </Listeners>
- </ext:Button>
- </Items>
- </ext:Toolbar>
- </TopBar>
- <ColumnModel ID="ColumnModel1" runat="server">
- <Columns>
- <ext:Column ColumnID="wzmc" DataIndex="wzmc" Header="物资名称" Align="Center" Sortable="false">
- <Editor>
- <ext:TextField ID="TextField1" runat="server" />
- </Editor>
- </ext:Column>
- <ext:Column ColumnID="ggxh" DataIndex="ggxh" Header="规格型号" Align="Center" Sortable="false">
- <Editor>
- <ext:TextField ID="TextField2" runat="server" />
- </Editor>
- </ext:Column>
- <ext:Column ColumnID="bcdd" DataIndex="bcdd" Header="保存地点" Align="Center" Sortable="false">
- <Editor>
- <ext:TextField ID="TextField3" runat="server" />
- </Editor>
- </ext:Column>
- <ext:Column ColumnID="sccj" DataIndex="sccj" Header="生产厂家" Align="Center" Sortable="false">
- <Editor>
- <ext:TextField ID="TextField4" runat="server" />
- </Editor>
- </ext:Column>
- <ext:Column ColumnID="jxs" DataIndex="jxs" Header="经销商" Align="Center" Sortable="false">
- <Editor>
- <ext:TextField ID="TextField5" runat="server" />
- </Editor>
- </ext:Column>
- <ext:Column ColumnID="zzs" DataIndex="zzs" Header="制造商" Align="Center" Sortable="false">
- <Editor>
- <ext:TextField ID="TextField6" runat="server" />
- </Editor>
- </ext:Column>
- <ext:Column ColumnID="isny" DataIndex="isny" Header="是否为耐用品" Align="Center" Sortable="false">
- <Editor>
- <ext:ComboBox ID="TextField7" runat="server">
- <Items>
- <ext:ListItem Text="是" Value="是" />
- <ext:ListItem Text="否" Value="否" />
- </Items>
- </ext:ComboBox>
- </Editor>
- </ext:Column>
- <ext:Column ColumnID="jldw" DataIndex="jldw" Header="计量单位" Align="Center" Sortable="false">
- <Editor>
- <ext:ComboBox ID="ComboBox4" runat="server">
- <Items>
- <ext:ListItem Text="方" Value="方" />
- <ext:ListItem Text="公斤" Value="公斤" />
- <ext:ListItem Text="发" Value="发" />
- <ext:ListItem Text="根" Value="根" />
- <ext:ListItem Text="台" Value="台" />
- <ext:ListItem Text="灯" Value="灯" />
- <ext:ListItem Text="吨" Value="顿" />
- <ext:ListItem Text="米" Value="米" />
- <ext:ListItem Text="鞋" Value="鞋" />
- <ext:ListItem Text="套" Value="套" />
- <ext:ListItem Text="块" Value="块" />
- <ext:ListItem Text="辆" Value="辆" />
- <ext:ListItem Text="个" Value="个" />
- <ext:ListItem Text="把" Value="把" />
- </Items>
- </ext:ComboBox>
- </Editor>
- </ext:Column>
- <ext:Column ColumnID="cph" DataIndex="cph" Header="车牌号" Align="Center" Sortable="false">
- <Editor>
- <ext:TextField ID="TextField12" runat="server" />
- </Editor>
- </ext:Column>
- <ext:Column ColumnID="djgl" DataIndex="djgl" Header="电机功率" Sortable="false">
- <Editor>
- <ext:TextField ID="TextField13" runat="server" />
- </Editor>
- </ext:Column>
- <ext:Column ColumnID="zjs" DataIndex="jzs" Header="间(座)数" Align="Center" Sortable="false">
- <Editor>
- <ext:NumberField ID="TextField14" runat="server" />
- </Editor>
- </ext:Column>
- <ext:Column ColumnID="nx" DataIndex="nx" Header="使用年限" Align="Center" Sortable="false">
- <Editor>
- <ext:SpinnerField ID="SpinnerField2" runat="server" MinValue="1" MaxValue="100" AllowDecimals="true"
- DecimalPrecision="1" Accelerate="true" />
- </Editor>
- </ext:Column>
- <ext:Column ColumnID="scrq" DataIndex="scrq" Header="生产日期" Align="Center" Sortable="false">
- <Editor>
- <ext:DateField ID="TextField9" runat="server" />
- </Editor>
- <Renderer Fn="Ext.util.Format.dateRenderer('Y-m-d')" />
- </ext:Column>
- <ext:Column ColumnID="dqr" DataIndex="dqr" Header="到期日" Align="Center" Sortable="false">
- <Editor>
- <ext:DateField ID="TextField10" runat="server" />
- </Editor>
- <Renderer Fn="Ext.util.Format.dateRenderer('Y-m-d')" />
- </ext:Column>
- <ext:Column ColumnID="bz" DataIndex="bz" Header="备注" Align="Center" Sortable="false">
- <Editor>
- <ext:TextField ID="TextField11" runat="server" />
- </Editor>
- </ext:Column>
- </Columns>
- </ColumnModel>
- <BottomBar>
- <ext:PagingToolbar runat="server" ID="PagingToolbar1" PageSize="20" StoreID="StoreDeptDetailList">
- </ext:PagingToolbar>
- </BottomBar>
- <SelectionModel>
- <ext:RowSelectionModel ID="RowSelectionModel1" runat="server">
- </ext:RowSelectionModel>
- </SelectionModel>
- <LoadMask ShowMask="true" />
- </ext:GridPanel>
- </Items>
- </ext:Panel>
- </Items>
- </ext:Viewport>
复制代码
后台代码
- DataTable dt = new DataTable();
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack && !X.IsAjaxRequest)
- {
- BuildTree(this.treePanel.Root);
- Hidden();
- }
- }
- #region 创建树
- //添加节点
- private Ext.Net.TreeNodeCollection BuildTree(Ext.Net.TreeNodeCollection nodes)
- {
- try
- {
- if (nodes == null)
- {
- nodes = new Ext.Net.TreeNodeCollection();
- }
- dt = wzflBLL.Instance.getALlwzml();
- DataRow[] drx = dt.Select(" FatherCode=''");
- Ext.Net.TreeNode root = new Ext.Net.TreeNode();
- root.NodeID = drx[0]["wzdm"].ToString();
- root.Text = drx[0]["wzmc"].ToString();
- root.Qtip = drx[0]["wzmc"].ToString();
- root.Expanded = true;
- root.Draggable = false;
- root.HrefTarget = drx[0]["wzdm"].ToString();
- nodes.Add(root);
- //添加相应子节点
- this.AddNodes(root);
- //ResourceManager1.AddScript("RefreshTree();");
- return nodes;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- //添加子节点
- private void AddNodes(Ext.Net.TreeNode parent)
- {
- DataRow[] drx = dt.Select();
- drx = dt.Select("FatherCode='" + parent.NodeID + "'");
- if (drx.Length == 0)
- {
- return;
- }
- foreach (DataRow dr in drx)
- {
- Ext.Net.TreeNode node = new Ext.Net.TreeNode();
- node.NodeID = dr["wzdm"].ToString();
- node.Text = dr["wzmc"].ToString();
- node.Qtip = dr["wzmc"].ToString();
- node.HrefTarget = dr["wzdm"].ToString();
- parent.Nodes.Add(node);
- AddNodes(node);
- }
- }
- #endregion
- //NODE点击事件
- [DirectMethod]
- public void NodeClick(string nodeID)
- {
- hdPid.Text = nodeID;
- String wzdm = "";
- //根据选中的树节点 来动态隐藏列
- if (hdPid.Text != "")
- {
- wzdm = wzmxBLL.getMaxFahterCode(hdPid.Text);
- }
- if (wzdm == "3")
- {
- gpFuncsList.ColumnModel.SetHidden(8, false);
- gpFuncsList.ColumnModel.SetHidden(9, false);
- gpFuncsList.ColumnModel.SetHidden(10, false);
- gpFuncsList.ColumnModel.SetHidden(6, true);
- }
- else if (wzdm == "2")
- {
- gpFuncsList.ColumnModel.SetHidden(6, false);
- gpFuncsList.ColumnModel.SetHidden(8, true);
- gpFuncsList.ColumnModel.SetHidden(9, true);
- gpFuncsList.ColumnModel.SetHidden(10, true);
- }
- else
- {
- gpFuncsList.ColumnModel.SetHidden(6, true);
- gpFuncsList.ColumnModel.SetHidden(8, true);
- gpFuncsList.ColumnModel.SetHidden(9, true);
- gpFuncsList.ColumnModel.SetHidden(10, true);
- }
- List<wzmxEntity> list = wzmxBLL.Instance.GetEntities(" where 1=1 and fldm='" + nodeID + "'");
- StoreDeptDetailList.DataSource = list;
- StoreDeptDetailList.DataBind();
- }
- protected void Hidden()
- {
- gpFuncsList.ColumnModel.SetHidden(6, true);
- gpFuncsList.ColumnModel.SetHidden(8, true);
- gpFuncsList.ColumnModel.SetHidden(9, true);
- gpFuncsList.ColumnModel.SetHidden(10, true);
- }
- protected void StoreChanged(object sender, BeforeStoreChangedEventArgs e)
- {
- ChangeRecords<wzmxEntity> persons = e.DataHandler.ObjectData<wzmxEntity>();
- foreach (wzmxEntity created in persons.Created)
- {
- wzmxEntity entity = created;
- entity.dwdm = Request.Cookies["danwei"].Value.Trim();
- entity.bmdm = Request.Cookies["bumen"].Value.Trim();
- entity.fldm = hdPid.Text;
- entity.wzdm = wzrkmlDal.GetNumber("008", "");
- wzmxBLL.Instance.Insert(ref entity);
- }
- foreach (wzmxEntity updated in persons.Updated)
- {
- wzmxBLL.Instance.Update(updated);
- }
- e.Cancel = true;
- }
- }
http://www.ext.net.cn/forum.php?mod=viewthread&tid=1498&extra=page%3D4