How to use Eval ("x") value in ListView

I am wondering how can I use Eval values ​​in a ListView? I mean displaying it as the text is simple enough even sending it to code with some parameters in case of a button click, for example. But how do I actually use this information like in the aspx page without using any fired events?

Basically I get an Eval, which is the number of products in stock. Now, based on that number, I'll either show the dynamic Add to Cart link or not. But I just can't seem to find a way to touch storage data. This is undoubtedly a newbie question, but I cannot find the answer to all of this.

Thank.

+2


source to share


2 answers


Wrap the Eval call :

Markup:

 <asp:LinkButton id="whatever" runat="server" 
     Visible='<%# ShowHideLink(Eval("Storage")) %>' ..etc />    

      



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 > 10) //whatever your biz logic is
    {
        result = true;
    }

    return result;
}

      

+2


source


I don't think you can do this without using listview events. You should be able to use the ItemInserting event on the list to hide or show the Add to Cart link.



0


source







All Articles