How to call a function on a databound value in ListView

Wrap your Eval call:

Markup: <asp:LinkButton id=”whatever” runat=”server” Visible=’’<%# ShowHideLink(Eval(“Storage”)) %>

Code-Behind:

protected bool ShowHideLink(object obj)
{
bool result = false;
//cast obj to whatever datatype it is
int numOfProducts = (int)obj;

//do some evaluating
if(numOfProducts &gt; 10) //whatever your biz logic is
{
    result = true;
}

return result;
}

reference: https://stackoverflow.com/questions/1530704/how-to-use-evalx-value-in-listview

Jason Kulatunga

Devops & Infrastructure guy @Gusto (ex-Adobe). I write about, and play with, all sorts of new tech. All opinions are my own.

San Francisco, CA blog.thesparktree.com

Subscribe to Sparktree

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!