【发布时间】:2011-04-27 01:50:41
【问题描述】:
我正在使用以下代码使我的 gridview 的整行都可点击:
protected void gridMSDS_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.textDecoration='underline';this.style.backgroundColor='#EEFF00'";
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';this.style.backgroundColor='White'";
e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.gridMSDS, "Select$" + e.Row.RowIndex);
}
}
效果很好,除了现在我想为网格添加编辑功能。这可行,但是当我同时打开行可单击和编辑功能时,单击“编辑”链接按钮通常会触发行单击事件,反之亦然。
那么,除了指定的列之外,我怎样才能保持行可点击?
更新: 这是我正在使用的。
基于贾斯汀的解决方案:
List<int> notClickable = new List<int>();
{
notClickable.Add(0);
notClickable.Add(2);
}
for(int i = 0; i < e.Row.Cells.Count; i++)
{
if (!notClickable.Contains(i))
{
e.Row.Cells[i].Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(this.gridMSDS, "Select$" + e.Row.RowIndex);
}
}
【问题讨论】: