存在问题:由于双击之前会触发单击,从而无法注册双击事件。
解决思路:如何在点击一次后在N秒内未再次点击,将视为单击,否则为双击
js:
function ClickMouse(url)
{
var msgID=url;
var expiration =new Date((new Date).getTime()+1000*60000);
document.cookie="msgID="+msgID+";expires="+expiration.toGMTString()+";path=/";
//触发后台Button1按钮事件,延迟时间为1秒
setTimeout("__doPostBack('Button1','')",1000);
}
c#:
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.Cells.Count > 0) e.Row.Cells[0].Style.Add("display", "none");
if (e.Row.Cells.Count > 1) e.Row.Cells[1].Style.Add("display", "none");
if (e.Row.Cells.Count > 3) e.Row.Cells[3].Style.Add("display", "none");
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("ondblclick", this.Page.GetPostBackClientEvent(this, "4;" + e.Row.Cells[1].Text+";双"));
string url = "4," + e.Row.Cells[1].Text + "," + e.Row.Cells[0].Text;
e.Row.Attributes["onclick"] = "javascript:ClickMouse('" + url + "')";
e.Row.Cells[2].Attributes.Add("title", e.Row.Cells[2].Text);
if (e.Row.Cells[2].Text.Length > 40)
{
e.Row.Cells[2].Text = e.Row.Cells[2].Text.Substring(0, 40) + "...";
}
}
}
双击:
public void RaisePostBackEvent(string eventArgument)
{
}
单击:
protected void Button1_Click(object sender, EventArgs e)
{
}
除此之为也可以通过在GridView列上注册事件
if (GVt.Rows.Count > 0)
{
for (int i = 0; i < GV.Rows.Count; i++)
{
GV.Rows[i].Cells[3].Attributes.Add("onclick", "ClickMouse('" + url + "')");
GV.Rows[i].Cells[4].Attributes.Add("onclick", "ClickMouse('" + url + "')");
GV.Rows[i].Cells[5].Attributes.Add("onclick", "ClickMouse('" + url + "')");
GV.Rows[i].Style.Add("cursor", "hand");