简体   繁体   中英

Adding 'All' option to DropDownlist ASP.NET

So I have a drop down list(ASP.NET) with some values retrieved from sqldatasource. And I added a item name 'ALL' with a value -1 to retrieve all the values in that field(the field is varchar). But it do-sent work. Please help how can i get all the values instead of a specific one.

the 'All' Value is -1 witch is passed to the parameter @NAME but it do-sent work

Query:

 SELECT USERINFO.USERID, USERINFO.NAME, USERINFO.TITLE,
        CHECKINOUT.CHECKTIME, CHECKINOUT.CHECKTYPE FROM USERINFO INNER JOIN
        CHECKINOUT ON USERINFO.USERID = CHECKINOUT.USERID WHERE NAME = @NAME
        AND CHECKTIME BETWEEN @startDate AND @endDate + ' 23:59:00.000'
SELECT USERINFO.USERID, USERINFO.NAME, USERINFO.TITLE,
        CHECKINOUT.CHECKTIME, CHECKINOUT.CHECKTYPE FROM USERINFO INNER JOIN
        CHECKINOUT ON USERINFO.USERID = CHECKINOUT.USERID 

        WHERE ( NAME = @NAME and @NAME<> -1 ) OR (@NAME = -1 and 1=1)

        AND CHECKTIME BETWEEN @startDate AND @endDate + ' 23:59:00.000'

Basically , the condition 1=1 is used to ignore condition in where clause for particular value passed to variable , in this case @NAME

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM