menu

Monday, May 23, 2011

Repeater Row Color on ItemDataBound Event

Repeater:

<asp:Repeater ID="rep_ServiceStatus" runat="server"
onitemcommand="rep_ServiceStatus_ItemCommand"
onitemdatabound="rep_ServiceStatus_ItemDataBound">
<HeaderTemplate>
<div class="container">
<div class="header">Change User Service Status</div>
<table title="Bank Account Information" class="mGrid" cellspacing="0" rules="all" border="1" id="ctl00_ContentPlaceHolder1_grd_BankAccount" style="border:1px solid #525252;width: 100%; background-color: #ffffff; margin-top: 5px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; border-collapse: collapse;">
<tbody>
<tr>
<th scope="col" style="padding-top: 4px; padding-right: 2px; padding-bottom: 4px; padding-left: 2px; color: #ffffff; background-image: initial; background-color: #424242; border-left-style: solid; border-left-width: 1px; border-left-color: #525252; font-size: 10px;">User ID</th>
<th scope="col" style="padding-top: 4px; padding-right: 2px; padding-bottom: 4px; padding-left: 2px; color: #ffffff; background-image: initial; background-color: #424242; border-left-style: solid; border-left-width: 1px; border-left-color: #525252; font-size: 10px;">Service ID</th>
<th scope="col" style="padding-top: 4px; padding-right: 2px; padding-bottom: 4px; padding-left: 2px; color: #ffffff; background-image: initial; background-color: #424242; border-left-style: solid; border-left-width: 1px; border-left-color: #525252; font-size: 10px;">Registration Request Status</th>
<th scope="col" style="padding-top: 4px; padding-right: 2px; padding-bottom: 4px; padding-left: 2px; color: #ffffff; background-image: initial; background-color: #424242; border-left-style: solid; border-left-width: 1px; border-left-color: #525252; font-size: 10px;">Service Status</th>
<th scope="col" style="padding-top: 4px; padding-right: 2px; padding-bottom: 4px; padding-left: 2px; color: #ffffff; background-image: initial; background-color: #424242; border-left-style: solid; border-left-width: 1px; border-left-color: #525252; font-size: 10px;">Change Status</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr id="tr_Service" runat="server">
<td><%#Eval("UserID")%></td>
<td><%#Eval("ServiceID")%></td>
<td><%#Eval("RegistrationRequestStatus")%></td>
<td id="td_ServiceStatus" runat="server"><%#Eval("ServiceStatus")%></td>
<td><asp:LinkButton ID="lnk_ChangeStatus" runat="server" CommandName='<%#Eval("ServiceRegistrationID")%>' CommandArgument='<%#Eval("ServiceStatus")%>'>Change Status</asp:LinkButton></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</div>
</FooterTemplate>
</asp:Repeater>

ItemDataBound Event of Repeater

protected void rep_ServiceStatus_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
foreach (Control c in e.Item.Controls)
{
if (c is System.Web.UI.HtmlControls.HtmlTableRow)
{
HtmlTableRow tr = (HtmlTableRow)c;
foreach (Control c1 in tr.Controls)
{
LinkButton myLink = (LinkButton)c1.FindControl("lnk_ChangeStatus");
if (myLink.CommandArgument.ToString() == "Active")
{
tr.BgColor = "#99FFCC";
}
else if (myLink.CommandArgument.ToString() == "InActive")
{
tr.BgColor = "#FFCCFF";
}
}
}
}
}
}

No comments:

Post a Comment