Set Text Color by Column in a Repeater Control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a Repeater control bound to a DataSet that creates a table with 6
columns. The text displayed in one of the columns may need to be set to grey
instead of black.

The DataSet is held and manipulated in a separate class "ResponseData.cs".
This class has a method ".getTextColor(int whichColumn)", which will return a
HEX value for the text color.

In JSP, a simple solution would have been to add inline code e.g.
style="color: <%= responseData.getTextColor(x) %>". How can I get to the
style attribute in the table the Repeater builds and set the text color in
ASP.Net (1.1)?

Thank you.
 
Use the ItemDataBound event that fires after the data has been bound. Use
this to get a handle to the current row. Then set the colors for all the
cells. When it's finished rendering, it'll look how you want. Note that in
your declarative repeater definition, you'll want to use <asp:TableCell>
controls so you can FindControl on the id and get the right cell. Then you
can use .Attributes["style"] = . . .

Best regards,
Jeffrey Palermo
 
Thank you, I will try this.

Jeffrey Palermo said:
Use the ItemDataBound event that fires after the data has been bound. Use
this to get a handle to the current row. Then set the colors for all the
cells. When it's finished rendering, it'll look how you want. Note that in
your declarative repeater definition, you'll want to use <asp:TableCell>
controls so you can FindControl on the id and get the right cell. Then you
can use .Attributes["style"] = . . .

Best regards,
Jeffrey Palermo

ASP Yaboh said:
I have a Repeater control bound to a DataSet that creates a table with 6
columns. The text displayed in one of the columns may need to be set to grey
instead of black.

The DataSet is held and manipulated in a separate class "ResponseData.cs".
This class has a method ".getTextColor(int whichColumn)", which will return a
HEX value for the text color.

In JSP, a simple solution would have been to add inline code e.g.
style="color: <%= responseData.getTextColor(x) %>". How can I get to the
style attribute in the table the Repeater builds and set the text color in
ASP.Net (1.1)?

Thank you.
 
Back
Top