gridview

Posted by Shailu_net under ASP.NET on 3/5/2009 | Views : 1592 | Status : [Member] | Replies : 4
Hi ,
This is shailaja.please provide me code for filling gridview rows with color using applying condition on column in c#.net using sql server 2005




Responses

Posted by: Neeks on: 3/5/2009 [Member] Bronze

Up
0
Down
You can do conditional formatting using CSS classes. There are following Properties you can used in GridView.
1. CssClass: Provide the CSS Class Name for whole Grid.
2. AlternatingRowStyle-CssClass: Provide the CSS Class Name for Alternate Row
3. HeaderStyle-CssClass: Provide the Name of CSS Class which can be used for the Header.


Shailu_net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Majith on: 3/5/2009 [Member] Starter

Up
0
Down
Hi,

You can apply the color based on different conditions .Here i have select the Mouseover,Mouseout using javascript.

Click the GridView RowDataBound Event and write the code:

if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "javascript:return MOver(this);";
e.Row.Attributes["onmouseout"] = "javascript:return MOut(this);";
}
Javascript:

function MOver(id)

{
var appcolor;
appcolor= id.style.backgroundColor;

id.style.backgroundColor='#85C0D4';

}


Shailu_net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shailu_net on: 3/5/2009 [Member] Starter

Up
0
Down
hi
i have a student table which is having id,name,total,result columns.i displayed data in grid.if result is pass i want that row to be filled with green color.else fail fill with red
i want code for this

Shailu_net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Neeks on: 3/5/2009 [Member] Bronze

Up
0
Down
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

int columnNumber = 3; //Your column number where the Attribute Pass or Fail reside.

if ((e.Row.Cells[columnNumber].Text.Trim()) == "Pass")
{
e.Row.CssClass = "pass";
}
else
{
e.Row.CssClass = "fail";
}

}


For CSS file
Create two CSS class:
1. pass
2. fail


Shailu_net, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response