惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
J
Java Code Geeks
L
LangChain Blog
V
V2EX
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
博客园 - Franky
Microsoft Azure Blog
Microsoft Azure Blog
Jina AI
Jina AI
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
博客园 - 司徒正美
B
Blog
G
Google Developers Blog
Stack Overflow Blog
Stack Overflow Blog
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
Engineering at Meta
Engineering at Meta
MyScale Blog
MyScale Blog
有赞技术团队
有赞技术团队
Hugging Face - Blog
Hugging Face - Blog

博客园 - Niko

SQLServer使用注意规范 . windows2008 导出Excel 配置。 Web.config 数据库连接字符串加密 NHibernate.AdoNet.TooManyRowsAffectedException: Unexpected row count: 19; expected: 1 安装sql server 2008 注意事项 - Niko 添加 程序映射 链接服务器"(null)"的 OLE DB 访问接口 Microsoft Office Excel 不能访问文件 Win2008 检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件时失败解决方法 excel 汇入, SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问 - Niko 卸载 vs 2008 ASP.net 打印页面内容 - Niko - 博客园 asp.net 异步调用 MSSQL2005 建立分区 Asp.net2.0 defaultButton 不支持firefox解决方法 Rational Rose 安装破解, 和常见问题解决 Gridview 选中checkbox 时, 展开子节点, 同时选中父节点 - Niko Database diagram support objects cannot be installed because this database does not have a valid owner. ASP.NET动态生成控件问题。 - Niko - 博客园
Grid view 级联选择 - Niko
Niko · 2008-11-10 · via 博客园 - Niko

前台:

<script language="javascript">
        function postBackByObject()
        {
            var element = window.event.srcElement;
            if (element.tagName == "INPUT" && element.type == "checkbox")
            {
                var checkedState = element.checked;
                while (element.tagName != "TABLE")
                element = element.parentElement;

                UnCheck(element);
                element = element.nextSibling;
                if (element == null)
                return;

                var childTables = element.getElementsByTagName("TABLE");
                for (var tableIndex = 0; tableIndex < childTables.length; tableIndex++)
                Check(childTables[tableIndex], checkedState);
            }
        }

        function UnCheck(table)
        {
            if (table == null || table.rows[0].cells.length == 2) // This is the root
                return;
            var parentTable = table.parentElement.previousSibling; 
            Check(parentTable, false);
            UnCheck(parentTable);
        }

        function Check(table, checked)
        {
            var checkboxIndex = table.rows[0].cells.length - 1;    
            var cell = table.rows[0].cells[checkboxIndex];
            var checkboxes = cell.getElementsByTagName("INPUT");
            if (checkboxes.length == 1)
                checkboxes[0].checked = checked;
        }
</script>

后台:

  this._offerCounties.Attributes.Add("onclick", "postBackByObject()");

  public void BindCountriesTreeView()
        {
            _offerCounties.Nodes.Clear();
            List<OfferCountry> allCountries = BLLOffer.GetAllCountries();

            DataTable dtCounties = ConvertHelper.ToDataTable<OfferCountry>(allCountries, "Id", "Name", "ParentId");
            intiTree(_offerCounties.Nodes, "-2", dtCounties);

            List<OfferCountry> offerCountries = BLLOffer.GetOfferCounties(_offerId.Value.ToString());
            setOfferCountries(this._offerCounties.Nodes, offerCountries);
        }


        /// <summary>
        /// Bind the treeview
        /// </summary>
        /// <param name="Nds"></param>
        /// <param name="parentId"></param>
        /// <param name="dataSource"></param>
        private void intiTree(TreeNodeCollection Nds, string parentId, DataTable dataSource)
        {
            DataView dv = new DataView();          
            TreeNode tmpNd;
            string strId;

            dv.Table = dataSource;
            dv.RowFilter = "ParentId='" + parentId + "'";

            foreach (DataRowView objRow in dv)
            {
                tmpNd = new TreeNode();
                strId = objRow["Id"].ToString();
                tmpNd.Value = strId.ToString();
                tmpNd.Text = objRow["Name"].ToString();
                tmpNd.ShowCheckBox = true;
                Nds.Add(tmpNd);
                intiTree(Nds[Nds.Count - 1].ChildNodes, strId, dataSource);
            }
        } 

  /// <summary>
        /// Recursive the tree and get the countries checked.
        /// </summary>
        /// <param name="nodes"></param>
        /// <param name="checkedCountry"></param>
        private void RecursiveTreeView(TreeNodeCollection nodes, ref List<OfferCountry> checkedCountry)
        {
            foreach (TreeNode node in nodes)
            {
                if (node.Checked)
                {
                    if (node.ChildNodes.Count == 0)
                    {
                        OfferCountry offerCountry = new OfferCountry();
                        offerCountry.Id = node.Value.ToString();
                        offerCountry.OfferId = _offerId.Value.ToString();
                        checkedCountry.Add(offerCountry);
                    }
                }
                RecursiveTreeView(node.ChildNodes, ref checkedCountry);
            }
        }