Search code examples
asp.netcheckboxevaliif

Using iif function in checkbox


I am working in a project where I need to display data from database in a gridview. The gridview contains varchar fields could be whether YES or NO. So I want to display rather than the text, checkbox. When its YES check box will be checked, when its NO check box will be unchecked.

My asp.net

<asp:CheckBox ID="chkCheck" runat="server" Checked='<%#"IIF(Eval("Check")="YES",true,false)%>' Width="80px" Enabled="false"/>

I am getting this error:

Character constant must contain exactly one character.

Is there any alternative option would solve my issue?


Solution

  • You can simply use this (for VB.NET)

    Checked='<%#  Eval("Check")="YES" %>'
    

    For null values try

    Checked='<%#  Convert.ToString(Eval("Check"))="Yes" %>'