Instructor-led online courses in ASP.NET Core, ASP.NET MVC, and ASP.NET Design Patterns. Read more...
Instructor-led online courses in ASP.NET Core, ASP.NET MVC, and ASP.NET Design Patterns. Conducted by Bipin Joshi on weekends. More details are available here.

<%@ Page %>

Display Conditional Data In DataGrid Column

Introduction

Some times we need to display values in DataGrid column based on some conditions. For example if the database field value is NULL then you may want to display something like "Not Available" and the actual value if available. Such conditional display can be achieved by binding DataGrid column to a function. This code demo shows just that.

Example

For our example code we will use Northwind database that ships with SQL server. We will use Employees table. The table has many fields but we will use only two of them LastName and Region. The region field has some NULL values. Whenever this column is NULL we will display "Not Available" else we will display actual value of the region.

How to run the sample

Follow these instructions to run the demo:
  • Create a web project in VS.NET called ConditionalGrid
  • Unzip supplied files in the project folder
  • Add the files to the project
  • Modify database connection string in the code
  • Compile and run the application

Bipin Joshi is a software consultant, trainer, author and spiritual yoga mentor having 23+ years of experience in software development. He teaches online training courses in ASP.NET Core, Angular, and Design Patterns to individuals and small groups. He is a published author and has authored or co-authored books for Apress and Wrox press. Having embraced the Yoga way of life he also teaches Ajapa Yoga to interested individuals. To know more about him click here.

Get connected : Twitter  Facebook  Google+  LinkedIn

Posted On : 14 June 2002


Tags : ASP.NET Server Controls Data Controls


Subscribe to our newsletter

Get monthly email updates about new articles, tutorials, code samples, and how-tos getting added to our knowledge base.