zoukankan      html  css  js  c++  java
  • DropDownList 根据客户端的选择执行相关后台代码!

         实现思路:需要在下拉框的onchage客户端事件做相关处理,并且需要在页面放置一个hidvalue放置下拉框改变之前的索引值,用于

    在客户取消后回滚到之前选项。如果确定那么直接让下拉框进行提交  __doPostBack(“下拉框ID”,''); 具体实现代码如下:

       aspx: 

       <html xmlns="http://www.w3.org/1999/xhtml" >

          <head runat="server">    

            <title>Untitled Page</title>    

            <script language="javascript">   

                    function SelectedChange(ctl)        

                    {            

                       if(confirm("确认提交后台数据吗?") == false)            

                      {                

                           ctl.selectedIndex = document.getElementById('HidLastSelect').value;                

                           return false;            

                      }            

                       else            

                      {                

                          document.getElementById('HidLastSelect').value = ctl.selectedIndex;                

                          _doPostBack(''+ ctl.ClientID +'','');            

                       }        

                    }

           </script>

          </head>

        <body>     

                <form id="form1" runat="server">    

                       <div>        

                               <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">            

                                      <asp:ListItem>All</asp:ListItem>            

                                      <asp:ListItem>1</asp:ListItem>            

                                      <asp:ListItem>2</asp:ListItem>             
                              </asp:DropDownList>    

                       </div>     

                      <input type="hidden" id="HidLastSelect" value="0" runat="server" />    

                </form>

         </body>

      </html>

     cs:

       public partial class Default3 : System.Web.UI.Page {    

                protected void Page_Load(object sender, EventArgs e)     {               

                     DropDownList1.Attributes.Add("onchange", "return SelectedChange(this)");

                }   

               protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)     {      

                    Response.Write("changed");    

               }

      }

  • 相关阅读:
    [bzoj] 2565 最长双回文串
    [codeforces] 17E Palisection
    luogu P3267 [JLOI2016/SHOI2016] 侦查守卫
    181020-181021 模拟 题解
    luogu P2571 [SCOI2010]传送带
    poj1064 Cable master
    poj1422 Air Raid
    luogu P2512 [HAOI2008]糖果传递
    CF549H Degenerate Matrix
    左偏树基础教学
  • 原文地址:https://www.cnblogs.com/BeyondWJsel/p/2391929.html
Copyright © 2011-2022 走看看