zoukankan      html  css  js  c++  java
  • Double Click on Datagrid can be trapped


    Double click could be simulated by actaully investigating on how SELECT command works on DataGrid.
    The select command creates a <A> tag which runs the __doPostBack Java function at the client side script.
    The paramater of the __doPostBack actaully refers where the action was taken and the page is posted
    back to the server.

    So we will attach a double click event on the DataRows in the Datagrid and simulate the standard Click event.

    Lests check the following code for a DataGrid called MasterGrid. Where we trap the datagrid while each Items are being Created.
    Attached following function to ItemCreated Event by using the following code,
    this.MasterGrid.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler (this.MasterGrid_ItemCreated);

    The event function for the Item Created for the MasterGrid datagrid.
    private void MasterGrid_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    String DataGridID = ((DataGrid)sender).ID + "$"; // find the datagrid name and add a dollar sign

    if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem) || (e.Item.ItemType == ListItemType.SelectedItem) )
    {
    e.Item.Attributes.Add ("ondblclick", "javascript:__doPostBack('" + DataGridID + "_ctl" + (e.Item.ItemIndex+3).ToString() + "$_ctl0','')");
    }

    }

    This code creates the event ondblclick with each item of the datagrid and does the __doPostback exactly the same way Select Column would do in the datagrid.

    You have to understand that each item is actaully showns as <TR> in a table and each cells are actaully <TD>s. The Code actually attaches to
    the <TR>'s double click event.

    If you have examine the code carefully you could see that if you use "onclick" instead of "ondblclick" you could really simulate the SELECT command functionality without actaully showing the SELECT column in the daragrid. To implement this, you will need to add the SELECT column in the datagrid. you either have to have it visible or not visible on the Grid itself. If it is shown, remeber that the SELECT column will always trap the single click events as unusal. Rest of the area in the row will trap the double click event. The function for the SelectedIndexChanged of the datagrid will be executed on double Clicks as well as click on the SELECT column.

  • 相关阅读:
    Object.prototype.toString.call()进行类型判断
    JavaScript中的typeof操作符用法实例
    js ==与===区别(两个等号与三个等号)
    js nextSibling属性和previousSibling属性概述及使用注意
    Java 缓存技术之 ehcache
    不可不知 DDoS的攻击原理与防御方法
    jQuery的选择器中的通配符[id^='code']
    jquery $("[id$='d']").val();这句话什么意思?
    js 数组的操作
    【转】理解js中的原型链,prototype与__proto__的关系
  • 原文地址:https://www.cnblogs.com/hhq80/p/662681.html
Copyright © 2011-2022 走看看