互联网技术 · 2024年2月23日

TreeNodeCheckChanged事件的代码示例

这篇文章主要介绍了TreeNodeCheckChanged事件触发方法代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

这个事件不会主动postback,需要手动写javascript触发。对网上找到的方法做了些改进,增加UpdatePanel,以免页面不停的刷。这里就不考虑性能神马的了,因为既然项目已经允许选择使用TreeView服务器控件了,也就不要在乎多一个UpdatePanel了。

前台页面

<html>
<head runat=”server”>
  <title></title>

  <script type=”text/javascript”>
    function postBackByObject() {
      var o = window.event.srcElement;
      if (o.tagName == “INPUT” && o.type == “checkbox”) {
        //第一个参数写UpdatePanel的ID,否则就是整个页面刷了
        __doPostBack(“UpdatePanel1”, “”);
      }
    }
  </script>

</head>
<body>
  <form id=”form1″ runat=”server”>
    <asp:ScriptManager ID=”ScriptManager1″ runat=”server”>
    </asp:ScriptManager>
    <asp:UpdatePanel ID=”UpdatePanel1″ runat=”server”>
      <ContentTemplate>
        <asp:TreeView runat=”server” ID=”treeView1″
          OnTreeNodeCheckChanged=”treeView1_TreeNodeCheckChanged”>
        </asp:TreeView>
      </ContentTemplate>
    </asp:UpdatePanel>
  </form>
</body>
</html>

后台页面

protected void Page_Load(object sender, EventArgs e)
  {
    if (!IsPostBack)
    {
      treeView1.Attributes.Add(“onclick”, “postBackByObject()”);
    }
  }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

来源:脚本之家

链接:https://www.jb51.net/article/201293.htm

OpenMagic API

Need more than content? Move into the product flow.

If you are here for model access, pricing, developer docs, or the future API console, the dedicated product path now lives on api.openmagic.ai.

登录免费注册