ERP客户关系渠管理添加和修改联系人(二十一)
树形结构treeview 前端代码:
<form id="form1" runat="server"> <div> <asp:TreeView ID="TreeView1" runat="server"> </asp:TreeView> </div> </form>
后端代码:
public partial class ChannelList : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { CreateTreeVeiw(); } } DataSet ds; DataTable dt; private void CreateTreeVeiw() { ds = SqlComm.GetDataByCondition("BioErpCrmManageChannel", "ChannelID,SuperiorChannel,ChannelName", "1=1"); dt = new DataTable(); dt = ds.Tables[0]; DataView dv = new DataView(dt, "SuperiorChannel=0 or SuperiorChannel=null", "ChannelID", DataViewRowState.CurrentRows); //遍历父节点 foreach (DataRowView d in dv) { TreeNode n = new TreeNode(d["ChannelName"].ToString(), d["ChannelID"].ToString()); n.ImageToolTip = dt.TableName; TreeView1.Nodes.Add(n); n.Expanded = false; //根据父节点筛选出对应的子节点 dv = new DataView(dt, "SuperiorChannel='" + d["ChannelID"] + "'", "ChannelID", DataViewRowState.CurrentRows); if (dv.Count > 0) { CreateSubTreeView(n, dv); } } } /// <summary> /// 添加子项 /// </summary> /// <param name="n"></param> /// <param name="dv"></param> private void CreateSubTreeView(TreeNode n, DataView dv) { foreach (DataRowView d in dv) { TreeNode cn = new TreeNode(d["ChannelName"].ToString(), d["ChannelID"].ToString()); n.ChildNodes.Add(cn); DataView sdv = new DataView(dt, "SuperiorChannel='" + d["ChannelID"] + "'", "ChannelID", DataViewRowState.CurrentRows); if (sdv.Count > 0) { CreateSubTreeView(cn, sdv); } } } }
js代码:
function showChannel() { var re = showModalDialog("../PersonList/ChannelList.aspx", "", "dialogWidth=350px;dialogHeight=400px"); }
前端加载页面:
<td>上级渠道</td><td><asp:TextBox ID="txtJuridicalPerson" runat="server"></asp:TextBox> <input type="button" onclick="showChannel()" value="选择"/> </td>
显示页面的界面前端代码:
<script type="text/javascript"> function ReturnValue(noteid) { if (noteid != NaN || noteid != 0) { window.returnValue = noteid; window.close(); } else { window.returnValue = 0; window.close(); } } </script>
js代码:
function showChannel() { var re = showModalDialog("../../PersonList/ChannelList.aspx", "", "dialogWidth=350px;dialogHeight=400px"); txtSuperChannelID = document.getElementById("txtSuperChannelID") if (re != null) { if (txtSuperChannelID != null) { txtSuperChannelID.value = re; } else { txtSuperChannelID.value = "0"; } } else { txtSuperChannelID.value = "0"; } }
效果:
动态添加行:(代码)
<style type="text/css"> .style1 { height: 22px; } .style3 { width: 352px; } .style4 { width: 114px; } .style5 { width: 92px; } .linkmantable{ width:100%; border:solid 1px; border-collapse:collapse; } .linkmantable td{ border:solid 1px ;} .linkmantable input{ width:70px;} </style> <script type="text/javascript"> $(document).ready(function () { var i = 0; jQuery("#btnAddNew").click(function () { i++; tr = ''; tr = tr + ' <tr id="tr' + i + '">'; tr = tr + ' <td><input name="txtLinkMan1" MaxLength="10"></input></td>'; tr = tr + ' <td>'; tr = tr + ' <select name="ddlSex1" > <option Value="0">男</option> <option Value="1">女</option></select>'; tr = tr + ' </td>'; tr = tr + ' <td>'; tr = tr + ' <input name="txtBirthday1" onfocus="setday(this)" onclick="setday(this)" MaxLength="20"></input></td>'; tr = tr + ' <td><select name="ddlMainLink1"> <option Value="1">是</option> <option Value="0">否</option> </select></td>'; tr = tr + ' <td> <input name="txtOfficePhone" MaxLength="20" ></input></td>'; tr = tr + ' <td> <input name="txtMobile1" MaxLength="20" ></input></td>'; tr = tr + ' <td> <input name="txtEmail11" MaxLength="20"></input></td>'; tr = tr + ' <td> <input name="txtAddress1" MaxLength="50" ></input></td>'; tr = tr + ' <td> <input name="txtQQ1" MaxLength="15"></input></td>'; tr = tr + ' <td> <input name="txtRemark1" MaxLength="200"></input></td>'; tr = tr + ' </tr>'; $("#caption").before(tr); }); jQuery("#btnDelete").click(function () { $("#tr" + i).remove(); i--; }); }); </script>
控件代码:
<tr> <td colspan="4"> <table class="linkmantable"> <tr> <td>联系人</td> <td>性别</td> <td>生日</td> <td>是否主联系人</td> <td>办公室电话</td> <td>个人手机</td> <td>Email</td> <td>地址</td> <td>QQ</td> <td>备注</td> </tr> <tr> <td><input name="txtLinkMan1" MaxLength="10"></input></td> <td> <select name="ddlSex1" > <option Value="0">男</option> <option Value="1">女</option> </select> </td> <td> <input name="txtBirthday1" onfocus="setday(this)" onclick="setday(this)" MaxLength="20"></input></td> <td><select name="ddlMainLink1"> <option Value="1">是</option> <option Value="0">否</option> </select></td> <td> <input name="txtOfficePhone" MaxLength="20" ></input></td> <td> <input name="txtMobile1" MaxLength="20" ></input></td> <td> <input name="txtEmail11" MaxLength="20"></input></td> <td> <input name="txtAddress1" MaxLength="50" ></input></td> <td> <input name="txtQQ1" MaxLength="15"></input></td> <td> <input name="txtRemark1" MaxLength="200"></input></td> </tr> <tr id="caption"> <td colspan="10" style="text-align: right; padding-right: 20px;"> <input type="button" value="删除一行" id="btnDelete" /><input type="button" value="添加一行" id="btnAddNew" /> </td> </tr> </table> </td> </tr>