Click here to Skip to main content
14,392,016 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi can anyone help me out?
I wanna change the Gridview row color Based on Value.
Posted
Comments
SVT02 28-Feb-14 3:10am
   
try to use AlterneteitemTemplate With different color css class
Surendra0x2 28-Feb-14 3:14am
   
Thanks
Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi Try this in server side grid databound
protected void gvDevice_RowDataBound(object sender, GridViewRowEventArgs e)
{

	if ((e.Row.RowType == DataControlRowType.DataRow)) {
		Image imgStatuss = e.Row.FindControl("imgStatus");
		 

		string status = DataBinder.Eval(e.Row.DataItem, "IPAddress");

		try {

			Ping ping = new Ping();
			PingReply pingreply = ping.Send(status);
			string reply = pingreply.Status;

			if ((reply == 0)) {
				 
				e.Row.BackColor = Drawing.Color.Yellow;
			} else {
				 
				e.Row.BackColor = Drawing.Color.Blue;
			}
		} catch (Exception ex) {
			 
		}
	}
}


in above code i will get ip address form gridview and i ping ip address,i can ping that row change to yellow color,if not ping change to blue color.

i will get ip address from string status = DataBinder.Eval(e.Row.DataItem, "IPAddress");
i have ip address column in gridview and get that ip using e.Row.DataItem and assing in status,then i will ping ip address in status string,if it reply(successfully ping) 0 then row color change to yellow,i not get 0 then change to blue color

in ur excepetation get value form grid view and check that values and assign color for row

Regards
Aravind
   
Comments
Surendra0x2 28-Feb-14 4:40am
   
Thanks :)
Aravindba 28-Feb-14 4:50am
   
welcome...
Rate this:
Please Sign up or sign in to vote.

Solution 2

protected void gvrequests_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string strIsEnable = e.Row.Cells[8].Text;
            if (strIsEnable == "False")
            { e.Row.BackColor = System.Drawing.Color.LightBlue; }
        }
    }
   
Comments
Surendra0x2 28-Feb-14 4:41am
   
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100