Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

8/28/2017 Sql server, .

net and c# video tutorial: Design time and runtime formatting of gridview - Part 10

More Next Blog Create Blog Sign In

Sql server, .net and c# video tutorial


Free C#, .Net and Sql server video tutorial for beginners and intermediate programmers.

Support us .Net Basics C# SQL ASP.NET ADO.NET MVC Slides C# Programs Subscribe Buy DVD

Design time and runtime formatting of gridview - Part 10

Suggested Videos
Part 7 - Formatting asp.net gridview control
Part 8 - Formatting gridview using rowdatabound event
Part 9 - Formatting gridview based on row data
Best software training and placements in
marathahalli, bangalore. For further
details please call 09945699393.

GridView control provides several inbuilt styles to format different sections of the
CBSE Class 9 Maths
gridview. The following are some of the style properties and the sections they can
Number Systems
format.
ControlStyle - Use to apply the formatting on the entire gridview control
RowStyle - Use to format all rows in the gridview CPT Tutorial
AlternatingRowStyle - Use to format all alternating rows in the gridview Part 1 : Video | Text | Slides
HeaderStyle - Use to format the header of the gridview control
FooterStyle - Use to format the footer of the gridview control
Important Videos
EditRowStyle - Use to format when the row is in edit mode.
The Gift of Education

Web application for your business

By default, the footer of the girdview control is not visible. To show the footer, set How to become .NET developer
"ShowFooter" property of the gridview control to true.
Resources available to help you
If you are not very good at designing, then you may use "AutoFormat" feature of the
gridview control.
Dot Net Video Tutorials
Angular 2 Tutorial
These styles can be applied declaratively at design time or dynamically at runtime
based on the underlying data. At design time, the styles can be applied using properties
Design Patterns
window or directly in the HTML source.
ASP.NET Web API
Now, let us understand changing the styles dynamically based on underlying
data. I have tblEmployee table, as shown below. Bootstrap

AngularJS Tutorial

jQuery Tutorial

JavaScript with ASP.NET Tutorial

JavaScript Tutorial

Charts Tutorial
I want to display this data in a gridview control. All the employee rows, with salary
greater than 70,000 should have a "RED" background color and white font colour. LINQ
Obviously this cannot be done at design time. At runtime, we need to check the value in
"AnnualSalary" column for each row, and if it is greater than 70,000, then we need to LINQ to SQL
set the "BackColor" property of that row to "Red". This can be very easily achieved
LINQ to XML
using RowDataBound event. The output should be as shown below.
Entity Framework

http://csharp-video-tutorials.blogspot.in/2013/02/design-time-and-runtime-formatting-of.html 1/3
8/28/2017 Sql server, .net and c# video tutorial: Design time and runtime formatting of gridview - Part 10
WCF

ASP.NET Web Services

Dot Net Basics

C#

SQL Server

ADO.NET
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{ ASP.NET
// Loop thru each datarow in the gridview
if (e.Row.RowType == DataControlRowType.DataRow) GridView
{
// You can also retrieve salary using cell index in the row ASP.NET MVC
// Avoid using index, as this may not work correctly if the
Visual Studio Tips and Tricks
// order of columns is changed in the gridview control
// int salary = Convert.ToInt32(e.Row.Cells[2].Text); Dot Net Interview Questions
// Retrieve salary
int salary = Convert.ToInt32
(DataBinder.Eval(e.Row.DataItem, "AnnualSalary")); Slides
// If Salary > 70000, set your styles Entity Framework
if (salary > 70000)
{ WCF
e.Row.BackColor = System.Drawing.Color.Red;
ASP.NET Web Services
e.Row.ForeColor = System.Drawing.Color.White;
} Dot Net Basics
}
} C#

SQL Server

ADO.NET

ASP.NET

GridView

ASP.NET MVC

Visual Studio Tips and Tricks

Java Video Tutorials


Part 1 : Video | Text | Slides

Part 2 : Video | Text | Slides

Part 3 : Video | Text | Slides


No comments:
Interview Questions
Post a Comment
C#
If you like this website, please share with your friends on facebook and Google+ and
recommend us on google using the g+1 button on the top right hand corner. SQL Server

Written Test

http://csharp-video-tutorials.blogspot.in/2013/02/design-time-and-runtime-formatting-of.html 2/3

You might also like