RSS

Change color for RadGrid Rows

19 Dec

hi.

If you want to  change color of RadGrid Rows.Its Simple and Past Below Code on Code Behind after Giving Datasourse

customize Color according to the specific condition or column

//RadGrid RowLoaded Event

private void grduser_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
{
if (e.Row.DataContext != null)
{
callback cbf = e.Row.DataContext as callback;
if (cbf.Status == 2)
{
//callback finished
e.Row.SetValue(BackgroundProperty, new SolidColorBrush(FromHex(“#3c94f3”)));
}
else if (cbf.Calldatetime > DateTime.Now && cbf.Calldatetime < DateTime.Now.AddMinutes(30))
{
//call back time in half hour
e.Row.SetValue(BackgroundProperty, new SolidColorBrush(FromHex(“#a4d6ff”)));
}
else if (cbf.Calldatetime < DateTime.Now)
{
//call back time passed
e.Row.SetValue(BackgroundProperty, new SolidColorBrush(FromHex(“#E98A88”)));
}
}
}

//Create  Function which Return Row color
public Color FromHex(string hex)
{
string v = hex.TrimStart(‘#’);
if (v.Length > 8) //replace with number 8
return Colors.Blue;
if (v.Length == 6)
v = “FF” + v; // Add Alpha value
if (v.Length < 6) //replace with number 6
v = “FF” + v;
while (v.Length < 8) //replace with number 8
v += “0”;
Color c = new Color();
c.A = (byte)System.Convert.ToInt32(v.Substring(0, 2), 16);
c.R = (byte)System.Convert.ToInt32(v.Substring(2, 2), 16);
c.G = (byte)System.Convert.ToInt32(v.Substring(4, 2), 16);
c.B = (byte)System.Convert.ToInt32(v.Substring(6, 2), 16);
return c;
}

Advertisements
 
Leave a comment

Posted by on December 19, 2011 in Silverlight, Uncategorized

 

Tags: , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: