<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="Repeater1_ItemDataBound" >
<HeaderTemplate>
<table>
<tr><th>Title</th><th>Title ID</th><th>Type</th><th>Publisher ID</th><th>Price</th></tr>
</HeaderTemplate>
<ItemTemplate>
<tr id="Tr1" runat="server">
<td>
<asp:Label ID="lblTitle" runat="server" Text='<%# Eval("title") %>' />
</td>
<td>
<asp:Label ID="lbltitle_id" runat="server" Text='<%# Eval("title_id") %>' />
<%# Eval("title_id") %>
</td>
<td>
<asp:Label ID="lbltype" runat="server" Text='<%# Eval("type") %>' />
</td>
<td>
<asp:Label ID="lblpub_id" runat="server" Text='<%# Eval("pub_id") %>' />
</td>
<td>
<asp:Label ID="lblprice" runat="server" Text='<%# Eval("price")%>' />
</td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr> <td colspan="5" ><hr size="10" style="background-color:Azure;" /></td></tr>
</SeparatorTemplate>
<FooterTemplate> </table> </FooterTemplate>
</asp:Repeater>
codebehind :
protected void Repeater1_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)
{
Label mylabel = (Label)c1.FindControl("lblprice");
if (mylabel != null)
{
if (Convert.ToDecimal(mylabel.Text) >20)
{
tr.BgColor = "Red";
}
}
}
}
}
}
}
No comments:
Post a Comment