国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

ASP.NET中ListBox實現Double Click事件

2019-11-17 04:05:20
字體:
來源:轉載
供稿:網友
(1)在WEB頁面上加入JS腳本和存放ListBox事件的隱藏輸入框,LISTBOX是用來保存時間的名稱,在CS頁面用到:其JS代碼如下:

<script language="javascript">
     function ListBox1_DoubleClick() {
       /* we will change value of this hidden field so  that inpage load event we can identify event.
       */
        document.forms[0].ListBox1Hidden.value = "doubleclicked";
        document.forms[0].submit();
     }
</script>

(2)將asp.net控件LISTBOX中加入雙擊事件聲明如下:

<asp:ListBox id="ListBox1"
                     ondblclick="ListBox1_DoubleClick()" runat="server">
                 <asp:ListItem Value="1">One</asp:ListItem>
                 <asp:ListItem Value="2">Two</asp:ListItem>
                 <asp:ListItem Value="3">Three</asp:ListItem>
                 <asp:ListItem Value="4">Four</asp:ListItem>
             </asp:ListBox>
(3)在WEB窗體加載的時候執行如下代碼(即雙擊LISTBOX中ITEM后執行的內容),

if(Request.Params["ListBox1Hidden"] != null
     && (string)Request.Params["ListBox1Hidden"] == "doubleclicked" )

{
    //the Listwas double click Event
    }
    }

例子如下:

<html>
<head>
     <script language="Javascript">
     function ListBox1_DoubleClick() {
       /* we will change value of this hidden field so

    that in
    page load event we can identify event.
            */
        document.forms[0].ListBox1Hidden.value = "doubleclicked";
        document.forms[0].submit();
     }
</script>
</head>
<body>
     <form runat="server">
         <div>Double click on Listbox
             <br />
             <asp:ListBox id="ListBox1"
                     ondblclick="ListBox1_DoubleClick()" runat="server">
                 <asp:ListItem Value="1">One</asp:ListItem>
                 <asp:ListItem Value="2">Two</asp:ListItem>
                 <asp:ListItem Value="3">Three</asp:ListItem>
                 <asp:ListItem Value="4">Four</asp:ListItem>
             </asp:ListBox>
             <input type="hidden" name="ListBox1Hidden" />
         </div>
         <div>click on button
             <br />
             <asp:Button id="Button1" onclick="Button1_Click"
                 runat="server" Text="Button"/>
         </div>
     </form>
</body>
</html>WEB窗體加載時候執行下列代碼就能實現雙擊ListBox中Item執行一些操作void Page_Load(Object sender, EventArgs e){
   if(Request.Params["ListBox1Hidden"] != null
     && (string)Request.Params["ListBox1Hidden"] == "doubleclicked") {
    //This means It was double click
     Response.Write("Double Click was fired selected item is "
     + ListBox1.SelectedItem.Text);
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永平县| 营山县| 长垣县| 哈密市| 郎溪县| 颍上县| 马龙县| 修水县| 台前县| 犍为县| 河池市| 简阳市| 鹤峰县| 溆浦县| 刚察县| 年辖:市辖区| 横峰县| 庆云县| 土默特右旗| 临夏县| 凤冈县| 平湖市| 尼木县| 凌源市| 黑河市| 林口县| 威海市| 丰城市| 襄樊市| 东兴市| 曲水县| 德化县| 扎兰屯市| 鹰潭市| 平凉市| 徐闻县| 刚察县| 昌吉市| 乌拉特前旗| 襄城县| 白山市|