{
string strCompanyStatus = string.Empty;
if (iStatus == 2 || iStatus == 3)
{
//foreach (RepeaterItem ri in rptCompanies.Items)
//{
// if (((Label)ri.FindControl("RowStatus")).Value == '2')
// foreach (Control ctl in rptCompanies.Controls[iStatus].Controls)
// {
// if (!ctl.GetType().Equals(typeof(Label)))
// continue;
// ((Label)ctl).ForeColor = System.Drawing.Color.Red;
// }
//}
return "style='backGround-color:red'";
}
return strCompanyStatus = iStatus == 1 ? "Active" : "InActive";
}
#endregion
<%# CompanyStatus((Int32)DataBinder.Eval(Container.DataItem, ("RowStatus")))%>
This is basicaly what im looking for. if the status is 2 or 3, The forecolor of that item for the repeater must appear in red, and yes im newish :) . Using Visual 2010, C#, asp.net. Windows 7.?
Satyapriya NayakPosted Nov 29, 2011, 4:00 AM
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = CreateDataSource();
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
}
protected DataTable CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr = null;
dt.Columns.Add(new DataColumn("ID", typeof(string)));
dt.Columns.Add(new DataColumn("status", typeof(string)));
dt.Columns.Add(new DataColumn("name", typeof(string)));
dt.Columns.Add(new DataColumn("address", typeof(string)));
dr = dt.NewRow();
dr["ID"] = "E001";
dr["status"] = "1";
dr["name"] = "Raj";
dr["address"] = "pune";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["ID"] = "E002";
dr["status"] = "2";
dr["name"] = "ravi";
dr["address"] = "mumbai";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["ID"] = "E003";
dr["status"] = "3";
dr["name"] = "rahul";
dr["address"] = "puri";
dt.Rows.Add(dr);
return dt;
}
public string GetRowColor(object obj)
{
string color = "white";
if (!string.IsNullOrEmpty(obj.ToString()))
{
string status = obj.ToString();
switch (status)
{
case "1":
color = "red";
break;
case "2":
color = "green";
break;
case "3":
color = "blue";
break;
default:
color = "white";
break;
}
}
return color;
}
}
Thanks
If this post helps you mark it as answer