Reputation: 4385
I have a gridview with a Select button in every row. How do I change the properties of this button programmatically? For example if the Party value of the row is Republican, I want the Select button to be Red; otherwise I want it to be Blue.
Thanks for any info.
Upvotes: 2
Views: 1787
Reputation: 30152
In your code (assuming server side) you need to get a reference to that row and then call FindControl passing in your buttons name. Then you can set whatever properties on it (css class, color, etc)
See this posting for details:
Accessing the different controls inside a GridView control
Upvotes: 2
Reputation: 14781
Try using Expressions:
<asp:Button ... BackColor=<%# Eval("Party") = "Republican" ? "Red" : "Blue" %> ... />
Here, the BackColor
property will take the appropriate value based on the Party
value whenever a RowDataBound
event gets fired ..
Upvotes: 3