I have a gridview. its data source is a datatable that is loaded from the database. In this gridview, i have a template column.
<asp:TemplateField HeaderText="Product Type" SortExpression="ProductID">
<ItemStyle CssClass="MP-table-tb-display-item" />
<ItemTemplate>
<div class="MP-table-tb-display-main">
<asp:LinkButton ID="lnkview" CommandArgument='<%# Eval("ProductID") %>' CommandName="Viewproduct"
runat="server" CausesValidation="False" OnClick="lnkview_Click"><h4>
<%# Eval("Name") %>
</h4>
</asp:LinkButton>
</div>
<br />
<div class="MP-table-tb-display">
<p>
<span>KEY</span><%# Eval("[product_type_key]") %></p>
<br />
<a target="_blank" href='<%# Eval("SourceURL") %>'>Source</a>
</div>
</ItemTemplate>
</asp:TemplateField>
In this I want Source hyperlink only show when data available into <%# Eval("SourceURL") %>. If I am not able to get the SourceURL value into RowDatabound Event . Please Guide me.
I plan for this too but this is not working properly.
<a target="_blank" href=' <%= Eval("SourceURL")!=null ? Eval("SourceURL") : "style='display: none'" %> />'> Source</a>
use this instead
Similarly you could use the
<a>tag to control its visiblity. The if condition would go in Style attribue and not in href attribute. Something like this