Archive

Posts Tagged ‘gridview’

Running Total In Gridview Footer in Asp.net

April 26, 2010 4 comments

When we want to display running total in gridview footer, use the following methods:

1) Using gridview row data bound:

http://csharpdotnetfreak.blogspot.com/2009/07/display-total-in-gridview-footer.html

2) Using private method in codebehind:

http://aspalliance.com/782_CodeSnip_How_to_Display_Sum_Total_in_the_Footer_of_the_GridView_Control

Advertisements

Change Background color of last updated record in Gridview in Asp.net

November 24, 2009 Leave a comment

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

BindDetails();
GvMake.PageIndex = Convert.ToInt32(Session[“pgindex”]);

Css for that is as follows:

.UpdateRecordCss td
{

background-color: Green;
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);*/
}

Using Enum in Gridview in Asp.net

November 17, 2009 Leave a comment

Lets say we want to bind a gridview with table having Fields

1) Customer Name

2) Category

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
{

Sales= 0,

Marketing= 1,

Production= 2
}

Now in the gridview source in the template field write this code.

<asp:TemplateField HeaderText=”Category”>
<ItemTemplate>
<div>
<%# Enum.GetName(typeof(GlobalLibrary.Constants.Category),Convert.ToInt32(Eval(“Category”))) %>
</div>
</ItemTemplate>
</asp:TemplateField>

Here in Globallibray.Constants is my project with Constants Class.. you can replace it with yours..

Data Navigation with the ListView & GridView, DataPager and SliderExtender Controls

Listview – Its a new control in asp.net 3.5, similar to gridview but much more capabilities than gridview..
Also Datapager – a new control in asp.net 3.5 used for data paging.
SliderExtender – a control of ajax toolkit

Combining all these three you can do wonders…

Below is an example of listview with datapager and slider extender

http://mattberseth.com/blog/2007/12/data_navigation_with_the_listv.html

Another example is of gridview with dataper and slider extender

http://www.dotnetcurry.com/ShowArticle.aspx?ID=219

The above links has source code to download, you can also view the live demo and play with the example..