2

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.

2 Answers 2

3

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 ..

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.