We help IT Professionals succeed at work.

Using Conditional Operator in VB.NET -ASP.NET in GridView

Puneet Arora
Puneet Arora asked
on
How can we use conditional operator in following ..
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
    BackColor="White" BorderColor="#336699" BorderStyle="Solid" BorderWidth="1px"  
    CellPadding="0" CellSpacing="0" DataKeyNames="MessageID" Font-Size="10"
    Font-Names="Arial" GridLines="Vertical" Width="40%">
           
            <Columns>            
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:CheckBox ID="chkStatus" runat="server"
                            AutoPostBack="true" OnCheckedChanged="chkStatus_OnCheckedChanged"
                            Checked='<%# Convert.ToBoolean(Eval("Approved")) %>'
                            Text='<%# Eval("Approved").ToString().Equals("True") ? " Approved " : " Not Approved " %>' />
                    </ItemTemplate>                   
                </asp:TemplateField>
               
                <asp:BoundField DataField="MessageID" HeaderText="MessageID" />                   
                <asp:BoundField DataField="MessageSenderName" HeaderText="MessageSenderName"  />
            </Columns>
           
    <HeaderStyle BackColor="#336699" ForeColor="White" Height="20" />
          
</asp:GridView>

Open in new window

Comment
Watch Question

BRONZE EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
Change

Text='<%# Eval("Approved").ToString().Equals("True") ? " Approved " : " Not Approved " %>' />

to

Text='<%# IIF(Eval("Approved"), " Approved " , " Not Approved ") %>' />

Explore More ContentExplore courses, solutions, and other research materials related to this topic.