Solved

Repeater itemtemplate if then statement based on database value

Posted on 2008-06-17
2
1,096 Views
Last Modified: 2012-05-05
Hi,

I'm trying to setup an itemtemplate for a repeater.   What needs to happen is if the database field "inventory" equals 0, then the item should say "(backordered)" otherewise it should display a textbox someone can enter an amount they want to order.  I

 have no idea how to start this since I don't know how to get an if statement to use a database value without erroring out, or how to setup a function to call other database values from inside the repeater control.  I am using C# if that makes a difference.

Any help is appreciated
0
Comment
Question by:fwong1
2 Comments
 
LVL 13

Accepted Solution

by:
sm394 earned 250 total points
ID: 21811953
// IN CS
//========================================================
protected bool Display(object dataItem)
    {

        if ((string)DataBinder.Eval(dataItem, "inventory") == "0" )
            return false;
        else
            return true;

    }
========================================================
IN ASPX
Visible="<%# Display(Container.DataItem) %>"
//=======================================================
assuming you have two controls one label with  text backordered and one text
you can set them visible based on that if condition
0
 

Author Closing Comment

by:fwong1
ID: 31468166
That's genius...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now