医药CRM系统开发

自已做医药CRM系统有四年了,终于可以算个产品了,努力市场化,今年重种将医药营销的理念加入CRM

导航

Double Click on Datagrid can be trapped

Posted on 2007-03-03 13:29  hhq80  阅读(231)  评论(0编辑  收藏  举报


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.