Click here to Skip to main content
14,690,227 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi can anyone help me out?
I wanna change the Gridview row color Based on Value.
SVT02 28-Feb-14 3:10am
try to use AlterneteitemTemplate With different color css class
Surendra0x2 28-Feb-14 3:14am

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

Surendra0x2 28-Feb-14 4:40am
Thanks :)
Aravindba 28-Feb-14 4:50am
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; }
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900