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.

  • 相关阅读:
    Hunspell介绍及试用
    语音活性检测器py-webrtcvad安装使用
    Nginx处理请求的11个阶段(agentzh的Nginx 教程学习记录)
    搭建rsync服务并同步重要数据
    语料库基础学习
    解决SSH远程执行命令找不到环境变量的问题
    Centos7上安装、破解bamboo6.0.3
    Java代码走查具体考察点
    Bamboo基础概念
    安装OpenResty开发环境
  • 原文地址:https://www.cnblogs.com/hhq80/p/662681.html
Copyright © 2011-2022 走看看