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.

  • 相关阅读:
    django http请求request详解
    HTTP协议向服务器传参
    股票交易费用及复利计算公式
    scrapy初步使用
    通过 multiprocessing Pool 线程池加速爬虫的处理
    通过 PIL 和 Python-tesseract 模拟登陆
    BeautifulSoup
    xpath
    http 请求特殊字符
    HTTP cookies
  • 原文地址:https://www.cnblogs.com/hhq80/p/662681.html
Copyright © 2011-2022 走看看