views:

303

answers:

2

Hey,

I'm wondering how I can use the Eval values in a ListView? I mean displaying it as text is simple enough, even sending it to the codebehind via some parameters in a button click event for example. But how do I actually use that information as is on the aspx page without using any triggered events?

Basically I get an Eval("Storage") that contains the number of products in storage. Now based on that number I will either show a dynamic "Add to cart" linkbutton or not. But I simply cannot find a way to touch that storage information. This is undoubtedly a newbie question but I can't find an answer to this anywhere.

Thanks.

A: 

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

rip
+1  A: 

Wrap your 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;
}
rick schott