Nov 24, 2015

Ternary Operator in ASP.Net Gridview and JavaScript

Ternary Operator is used to test a condition.

Advantage of using this Ternary Operator we can skip multiple lines of code that used for IF..ELSE / SWITCH Statements at Some specific situations where there is no need to return values.

Syntax :
int i = 5.ToString() == "5" ? "Yes It's Five" : "No It's not Five";

Here 
// We are using ternary operator ?
// if the condition is true then its return "Yes It's Five"
// if the condition is false then its return "No It's not Five"

here output is "Yes It's Five".

recently i faced one situation in ASP.Net Gridview along with JavaScript Using in my project.

In Gridview i'm displaying Client Details along with EMail Ids and their passwords with ***** Symbols for passwords, but some of my clients Email Ids were too long with their names then gridview alignment problems came into picture and i need to show an alert when user clicks on password column in gridview.

Let's See ASP.Net Source Code







In JavaScript :




I hope you will enjoy this code.

Thanks & Regards
       RAJ