2017-05-02 4 views
0

私は完全な行をクリック可能にしたいグリッドビューを持っていますが、最後の列をクリック可能にしたくありません。 個々のセルにクリック可能性を個別に割り当てることはできますが、1つの列にカーソルを置いたときにその列の行だけが強調表示されているように見えません。 だから私はこれを行い、行のクリックを設定して最後の列から削除しますが、最後の列から属性を削除することはできません。それはまだクリック可能です。グリッドビューの行セルから属性を削除できません。 asp.net

私が問題をうまく説明し、私が欲しいものを手に入れたら教えてください。

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");    
    } 
} 

答えて

2

属性が存在しないため、最後のセルから属性を削除することはできません。属性は行レベル<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); 
    } 
} 
+0

を感謝し、私はセル当たりの属性を設定するときに我々は1列目を置くと、その後、その列のみの行がありませんがある場合として強調されています2番目の列のハイライト..それは良く見えません。達成するための他の方法は? – Sak

+0

ループ内のセルごとのクリック、行レベルのホバーのみを設定します。または、GridViewにcss:hoverを使用します。 – VDWWD

+0

ああ、ありがとう、ありがとう。私が試してみましょう。 – Sak

関連する問題