Using IF Then Else in Eval in ASP.NET

ASP.NET Comments Off on Using IF Then Else in Eval in ASP.NET

When using Eval in your gridview or datalist view, we will bind the coloumn value using the Eval statement. Sometimes we need to check if the value of the Eval exists so that we can take appropriate mesures. For example checking the image value if it does not exists then we can assign some default image.

only the the snippet is shown below

General If then else statement
If(condition1)
{
…..
….
}
else
{
……
}

using if then else in Eval using shortcut method


<asp:Image ID="Image1" ImageUrl='<%#!String.IsNullOrEmpty(Eval("ImageName").ToString())?"images/" +Eval("ImageName").ToString() : "images/imagenotavailable.jpg" %>' runat="server" />


Author

Search

Back to Top