2011-03-09 62 views
0

該行有一個LinkBut​​ton,單擊時需要突出顯示該行。以編程方式查找GridView行

到目前爲止的代碼:

protected void linkbutton1_Click(object sender, EventArgs e) 
{ 
    LinkButton l = (LinkButton)sender; 
    GridViewRow g = (GridViewRow)l.Parent; // what is the correct way to do this? 
    //g.Style etc etc 
} 

回答

0

利用GridView控件的RowCommand事件,而不是LinkBut​​ton的Click事件的。

然後你就可以對LinkBut​​ton的,如「HighlightRow」一CommandName並做類似如下:

Select Case e.CommandName 
    Case "HighlightRow" 
    e.item.row.attributes("class") = "highlight" 
End Select 

對不起它在VB.NET,而不是C#

1

首先是設置

for (int i = 0; i < GridView1.Rows.Count;i++) 
      GridView1.Rows[i].BackColor = System.Drawing.Color.White; 
GridView1.Rows[e.NewSelectedIndex].BackColor = System.Drawing.Color.Cornsilk; 
0

1)設置: 「的CommandName」 的LinkBut​​ton的屬性來在gridview的寫入的代碼下面的selectedIndexChanging事件 「選擇」,然後 命令名稱屬性爲「選擇」

2)選擇風格無論是在背後由@Raymond所示還是給設定的CssClass屬性爲 SelectedRowStyle的GridView來的CssClass =「selecterowstyle」

.selectedRowstyle { 代碼背景色:#EAEAEA; }

相關問題