2011-03-09 84 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; }

相关问题