zachvaldez
asked on
Change background color of a last 2 rows of repeater.One yellow ,one blue
I would like to change the background color of the 2 lasts rows in a repeater control. These are the total values.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
no, I call the rptforecast databind inside the dropdown_selectedchangedIn dex event
ASKER
Thanks, I added your code in the selectedchangedEvent hoping it would pick up from there but is not rendering the colors. Here is the code
dr = acct.GetGLForecastInfo(acctselected, fiscalyear);
if (dr.HasRows)
{
rptForeCast.DataSource = dr;
rptForeCast.DataBind();
dr.Close();
int lvl = rptForeCast.Items.Count;
RepeaterItem lastrow = rptForeCast.Items[lvl - 1];
foreach (Control ctl in lastrow.Controls)
{
if (ctl.GetType() == typeof(Label))
{
Label td = (Label)ctl;
td.BackColor = System.Drawing.Color.Yellow;
}
}
lastrow = rptForeCast.Items[lvl - 2];
foreach (Control ctl in lastrow.Controls)
{
if (ctl.GetType() == typeof(Label))
{
Label td = (Label)ctl;
td.BackColor = System.Drawing.Color.Blue;
}
}
}
}
is the item count correct after databind ?
do you have labels in your repeater or some other control ? my code only changes background of labels but should work for textboxes as well.
what happens if you copy the section of code to PreRender event ?
do you have labels in your repeater or some other control ? my code only changes background of labels but should work for textboxes as well.
what happens if you copy the section of code to PreRender event ?
ASKER
This is one thing I couldn't figure out quickly is to bring out the events of a repeater or any control in the page.
IN previous MS Visual Studio , all I have to do was to select the control and view code to expose the events. How do you do it for example, to quickly expose the repeater pre render event? Just a question.
IN previous MS Visual Studio , all I have to do was to select the control and view code to expose the events. How do you do it for example, to quickly expose the repeater pre render event? Just a question.
ASKER
I think I'm very close to it. This code colors yellow the last row but does not work for the row before the last row to red
{
HtmlTableRow row1 = (HtmlTableRow)(ri.FindControl("row_itemtemplate"));
RepeaterItem item = row1.NamingContainer as RepeaterItem;
int index = item.ItemIndex;
if(index==lastrow.ItemIndex-1)
{ row1.Attributes.Add("style", "background-color:red"); }
if (index == lastrow.ItemIndex)
{ row1.Attributes.Add("style", "background-color:yellow"); }
ASKER
last row and next to last row
sry dont understand..
in what event are you trying to set the colors ? is lastrow ever greater than index ?
post the code of the event where the colors are being set.
have you added a breakpoint on it to see what the values of index is ?
in what event are you trying to set the colors ? is lastrow ever greater than index ?
post the code of the event where the colors are being set.
have you added a breakpoint on it to see what the values of index is ?
ASKER
thanks!
ASKER
int lvl = rptForeCast.Items.Count;
since I store the variable, how can I change the background of the rows of the repeater.
lvl is the last row. change to yellow
lvl-1 is the second to last change to blue