简体   繁体   English

选择一个gridview行并更改该行的颜色

[英]selecting a gridview row and changing the color of that row

I have a gridview, I want the row of the gridview to be turned blue when the user clicks on the row and turned to the original color if the user chooses to click on another row. 我有一个gridview,我希望当用户单击该行时,gridview的行变为蓝色,如果用户选择单击另一行,则将其变为原始颜色。 so for .e,g 所以对于.e,g

Col1   Col2

1       Test1
2       Test2

if the user clicks on row1 then row 1 shoud be blue, but if the user chooses to click on row2 then Row1 should come back to its original color and row2 becomes blue. 如果用户单击行1,则行1应该是蓝色,但是如果用户选择单击行2,则行1应该回到其原始颜色,行2变为蓝色。

Any help will be appreciated. 任何帮助将不胜感激。

Thanks. 谢谢。

As default it sets the cell at which you click to blue. 默认情况下,它将单击的单元格设置为蓝色。 So to get entire row blue, there's an easy way do this: 因此,要使整个行变成蓝色,有一个简单的方法可以做到这一点:

Click on your gridview and go to its properties on the right side of the screen. 单击您的网格视图,然后转到屏幕右侧的属性。 There will be a Selection Mode property of gridView set it to FullRowSelect . 将有一个gridViewSelection Mode属性,将其设置为FullRowSelect

I is in the SelectedRowStyle BackColor. 我在SelectedRowStyle BackColor中。 You can set the color of the selected row there. 您可以在此处设置所选行的颜色。 I hope this helps. 我希望这有帮助。

Add SelectedRowStyle property to your GridView : SelectedRowStyle属性添加到您的GridView

<asp:GridView ID="GridView1" runat="server">      
     <SelectedRowStyle BackColor="Blue" />  Add this in your Gridview markup
        <Columns>  
          //
        </Columns>          
</asp:GridView>  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM