Show image only if Count of Records from Database is greater than one in ASP.Net

Last Reply on Apr 22, 2013 02:22 AM By RkHirpara

Posted on Apr 22, 2013 02:06 AM

Hi

I have 2 table in database

HOuse_info

Id

Name

City

Behcode

behcodeN

freg

1

Sara

Paris

1111

Free

1

2

Jack

Italy

1112

free

Null

 

and Black_list table

Id

Name

City

Behcode

behcodeN

freg

1

Sara

Paris

1111

Free

1

2

ana

India

1115

Free

Null

3

Micheal

Germany

2222

Special

1

 

I have 2 image in Information.aspx page

1-IMGfree

2-ImgBlackList

I want if in HOuse_info table user's BehcodeN='free' so it does

Imgfree.visible='true'

and if  that user's information be in Bleck_list tabel so it does  ImgBlackList .visible='true'

i.e

here user with behcode=1111 is in HOuse_info Table with BehcodeN='free' and this user is in Black_list Table too 

so both image visibility Should be true

But user with behcode=1112 is just in HOuse_info tabel so in this case it just  Imgfree.visibe=true

Now Below is Behindcode

 

 

 

 

 

 

 

 

    if (_dr["BehcodeN"].ToString().Trim() == "free")
                {
                    Imgfree.Visible = true;
                }

 

  if (_dr["Blacklist"].ToString().Trim() != null)
                {
                    Imgblacklist.Visible = true;
                }


SP

 

 

 

 

ALTER procedure [dbo].[View_user_info]

@Id int,@behcode nvarchar(10)
   
as
begin
select *,

(select Id from Black_list where Behcode=@behcode) Blacklist
from House_Info
where id=@Id or BehCode=@behcode
end

NOw problem is that here it show Imgblacklist Everytime I mean if users be in Black_list Table or They weren't in black_list table it show Imgblacklist

NOw what can i do?

Bestregards

Posted on Apr 22, 2013 02:22 AM

Hi Nedash,

please do the following way...,

(SELECT COUNT(Id) FROM Black_list WHERE Behcode=@behcode) Blacklist

And replace your whole if condition for Black list as

Imgblacklist.Visible = Convert.ToInt32(_dr["Blacklist"]) > 0;

(Dont change ImageFree if condition and its code as its working well).

Thanks and Regards,

Rk_Hirpara.