Reputation: 13824
I have a grid view that displays all of uploaded files of an employee (data from SQL DB).
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" AllowPaging="true" ShowFooter="false" PageSize="5"
CssClass="table" AlternatingRowStyle-BackColor="WhiteSmoke"
HeaderStyle-BackColor="#6C7A95" HeaderStyle-BorderColor="#666666" HeaderStyle-BorderStyle="Solid" HeaderStyle-BorderWidth="2" HeaderStyle-ForeColor="White"
OnPageIndexChanging="OnPaging" EmptyDataText="No Documents">
<Columns>
<asp:BoundField DataField="file_name" HeaderText="File Name" />
<asp:BoundField DataField="upload_date" HeaderText="Date (GMT -7)" />
<asp:BoundField DataField="file_status" HeaderText="Status" />
<asp:TemplateField HeaderText="Employee's Note">
<ItemTemplate>
<a data-original-title='<%# Eval("emp_note")%>' href="#" class="demo-cancel-click" rel="tooltip"><i class="icon-book"></i></a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The interface look like this:
The Employee's Note (emp_note) is an optional field (emp_note can be null in database), how can I make the "icon-book" disappear if the emp_note is empty in database?
I tried this but got error:
<a data-original-title='<%# Eval("emp_note")%>' href="#" class="demo-cancel-click" rel="tooltip"><i class="<%= Eval("emp_note") != null ? "icon-book" : ""%>"></i></a>
Upvotes: 2
Views: 1185
Reputation: 253
What about this:
<i class='<%# Eval("emp_note") != null ? (Eval("emp_note") == "b" ? "icon-book" : "icon-b") : ""%>'></i>
Upvotes: 1
Reputation: 56688
You have wrong quotes for the class
value of the i
tag. Also <%# %>
should be used there, just as for the a
:
<i class='<%# Eval("emp_note") != null ? "icon-book" : ""%>'></i>
Upvotes: 4