c# gridview row click

后端 未结 9 1931
野的像风
野的像风 2020-12-01 09:34

When I click on a row in my GridView, I want to go to a other page with the ID I get from the database.

In my RowCreated event I have the following line:

         


        
9条回答
  •  死守一世寂寞
    2020-12-01 10:02

    JohnB, Your code works very fine, i added just a little hack to avoid alternatingRowStyle ruining after mouseout.

    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=''");
    

    Changed to:

    e.Row.Attributes.Add("onmouseout", "if(" + e.Row.RowIndex + "% 2 == 0) { this.style.backgroundColor=''; } else { this.style.backgroundColor = '#E8F7EA'; }");
    

    If there's a better way to do it, please let me know, but it's working perfect for me.

    Greetings.

提交回复
热议问题