Here in this post,i m gonna show how to change background color of last updated record in gridview.
Normally what happens after we have updated any record we redirect or bind grid again, so grid comes to first page and we dont know which record we updated if there are many records.
Lets say we have a gridview with 15 records and paging of 5.
If we go to page 2 and click on “edit” link of 8th record in gridview and update that record, now after that we have to change the background row color of 8th record in gridview on 2nd page. So for that we have to maintain the primary key of that record and page index in session whenever we call edit method.
Now on gridview row databound you have to do this code:
protected void Gv_RowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
int id = Convert.ToInt32(Gv.DataKeys[e.Row.RowIndex].Value.ToString());
if (id == Convert.ToInt32(Session[“pkid”]))
e.Row.CssClass = “UpdateRecordCss”;
also after binding grid you have to maintain page index
GvMake.PageIndex = Convert.ToInt32(Session[“pgindex”]);
Css for that is as follows:
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=’#B09900′,EndColorStr=’#FFF192′); /*FILTER: progid:DXImageTransform.Microsoft.Alpha( style=1,opacity=25,finishOpacity=100,startX=0,finishX=100,startY=100,finishY=0);*/
Lets say we want to bind a gridview with table having Fields
1) Customer Name
Now in the database Category field is stored as tiny int like 0 or 1 or 2
0 Stands for Sales
1 Stands for Marketing
2 Stands for Production
So, now when the gridview is bind, it will display o,1 values. instead of this we want their respective category name to be displayed.
For this we define a ENUM as follows
public enum Category
Now in the gridview source in the template field write this code.
<%# Enum.GetName(typeof(GlobalLibrary.Constants.Category),Convert.ToInt32(Eval(“Category”))) %>
Here in Globallibray.Constants is my project with Constants Class.. you can replace it with yours..