Hi. I managed to get the desired result and my codes are as under:
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
foreach (DataListItem row in DataList1.Items)
{
if (row.ItemType == ListItemType.Item || row.ItemType == ListItemType.AlternatingItem)
{
using (SqlConnection scon1 = new SqlConnection(ConfigurationManager.ConnectionStrings["CS"].ConnectionString))
{
scon1.Open();
SqlCommand scmd = new SqlCommand("Select DISTINCT RegNo From B Where Status = 'Pending'", scon1);
SqlDataAdapter sda = new SqlDataAdapter(scmd);
DataTable dt1 = new DataTable();
sda.Fill(dt1);
Label lbl = (Label)e.Item.FindControl("RegNoLabel");
foreach (DataRow dr in dt1.Rows)
{
if (dr["RegNo"].ToString() == lbl.Text)
{
lbl.BackColor = System.Drawing.Color.Red;
}
}
}
}
}
}
Thanks again. Sat