• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 482
  • Last Modified:

Repeater Row BgColor odd even color

This should be pretty simple so here it is.

Just like with the Gridview you can make it have every other row a different color. This makes for a cleaner looking table and easier to read one at that.

Here is the code that I have (obviously not working.

 

Codebehind

protected void RowColor(object sender, string RowNum)

{


if (RowNum % 2 == 0)

{

return "blue";

}

else

{

return "red";

}

}

 

 

the ASPX

<ItemTemplate>

<tr bgcolor=<%# RowColor(Eval("answerid")) %>>

 

the current errors I get is

Error 1 No overload for method 'RowColor' takes '1' arguments C:\Documents and Settings\Scott\My Documents\MSDN\Learn Visual Web Developer 2005 Express Edition-C#-Lesson 13\Snapshot5\QuizCS\questions.aspx 113


Error 2 Operator '%' cannot be applied to operands of type 'string' and 'int' C:\Documents and Settings\Scott\My Documents\MSDN\Learn Visual Web Developer 2005 Express Edition-C#-Lesson 13\Snapshot5\QuizCS\questions.aspx.cs 61


Error 3 Since 'questions.RowColor(object, string)' returns void, a return keyword must not be followed by an object expression C:\Documents and Settings\Scott\My Documents\MSDN\Learn Visual Web Developer 2005 Express Edition-C#-Lesson 13\Snapshot5\QuizCS\questions.aspx.cs 63


Error 4 Since 'questions.RowColor(object, string)' returns void, a return keyword must not be followed by an object expression C:\Documents and Settings\Scott\My Documents\MSDN\Learn Visual Web Developer 2005 Express Edition-C#-Lesson 13\Snapshot5\QuizCS\questions.aspx.cs 67


Thank you in advance
0
Scripter25
Asked:
Scripter25
1 Solution
 
vbandaruCommented:
Obvisuoly one problem I see is You have declared your function to return void but is returning "Red" or "Blue".

I need more information on the type of control you are using.

0
 
Scripter25Author Commented:
Ok yes you are correct I did do the overall codebehind incorrectly. the overall answer though I found to be this

ItemTemplate       Defines the content and layout of items within the list. Required.

AlternatingItemTemplate             If defined, the AlternatingItemTemplate determines the content and layout of alternating items. If not defined, ItemTemplate is used.

You can set the color values on that and that will do all the work for you.

Now though seeing as how you did answer the question somewhat I do want to provide you with the points but I in order for that can you give me an example of code that would take in a value of integer and return a string value?

this would help alot
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now