![](/img/trans.png)
[英]Get index of row in GridView Control in Asp.net if i have a value of a cell from this row.?
[英]Cannot remove the attribute from row cell in gridview | asp.net
我有一個gridview,其中我希望完整的行是可單擊的,但是我只是不想最后一列是可單擊的。 我可以將可點擊性分別分配給每個單元格,但這看起來並不好,因為當我們將鼠標懸停在一個列上時,僅突出顯示了列行。 因此,我這樣做了,設置了該行的可點擊性並將其從最后一列中刪除,但是無法從最后一列中刪除該屬性。 它仍然是可單擊的。
如果我對這個問題的解釋很好,請告訴我,您能得到我想要的嗎?
protected void gvTables_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.color='blue';this.style.textDecoration='underline';";
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';this.style.color='black';";
e.Row.ToolTip = "Click to Edit";
e.Row.Attributes["onclick"] = this.Page.ClientScript.GetPostBackClientHyperlink(this.gvTables, "Select$" + e.Row.RowIndex);
e.Row.Cells[e.Row.Cells.Count - 1].Attributes.Remove("onmouseover");
e.Row.Cells[e.Row.Cells.Count - 1].Attributes.Remove("onmouseout");
e.Row.Cells[e.Row.Cells.Count - 1].ToolTip = "";
e.Row.Cells[e.Row.Cells.Count - 1].Attributes.Remove("onclick");
}
}
您不能從最后一個單元格中刪除屬性,因為它們不存在。 這些屬性是在行級別<tr>
而不是單元格級別<td>
。
您可以像這樣設置每個單元的屬性:
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.color='blue';this.style.textDecoration='underline';";
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';this.style.color='black';";
for (int i = 0; i < e.Row.Cells.Count - 1; i++)
{
e.Row.Cells[i].ToolTip = "Click to Edit";
e.Row.Cells[i].Attributes["onclick"] = this.Page.ClientScript.GetPostBackClientHyperlink(this.gvTables, "Select$" + e.Row.RowIndex);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.