2
Answers

check this "Where condition" for multiple column Search

Photo of Abhimanyu Singh

Abhimanyu Singh

11y
1.6k
1
Hello All here,

Please check the "where condition" in below mentioned Store procedure for fetching multiple column data on button click.

Actually i want that..search data should come on..when we are selecting Dropdown list first then/or email_id selection in text box...means we can select both together or seperatly..then serchin data should display in gridview on button click function..Please help me

Because its working only for dropdownlist selection not for email_id together or seperate selection

ALTER Procedure [dbo].[Usp_SearchUserDetails]  

@UserId int=NULL,
@UserType nvarchar(50)=NULL,
@FirstName nvarchar(50)=NULL,  
@EmailId nvarchar(50)=NULL,
@StateId nvarchar(10)=NULL,  
@DistrictId nvarchar(10)=NULL,
@SqlMsg nvarchar(Max)output

)  
As
BEGIN
SET @SqlMsg=''
DECLARE @strQuery nvarchar(max) 
BEGIN TRY
Select ROW_NUMBER()Over(Order By U.AddDate Desc) as SerialNo,
U.UserType,
U.EmailId,
U.FirstName,
U.LastName,
U.PhoneNo,
U.MobileNo,
U.[Address],
U.PinCode,
U.Company,
       U.StateId,
S.StateName,
D.DistrictName,
[Password],
CONVERT(Varchar,U.AddDate,103) as AddDate
from tblUser as U
inner join tblState as S
On U.StateId=S.StateId
Inner Join tblDistrict as D
on U.DistrictId=D.DistrictId
Where U.UserType IS NOT NULL AND (U.UserType=@UserType And U.ActiveFlag=1)or(U.UserType=@UserType And U.EmailId=@EmailId And U.ActiveFlag=1)
--Where (U.UserType=@UserType And U.ActiveFlag=1)And(U.EmailId=@EmailId And U.ActiveFlag=1)
END TRY
BEGIN CATCH
SET @SqlMsg=ERROR_MESSAGE()
END CATCH

END

Answers (2)

0
Photo of Dharmendra Singh
NA 179 34.6k 11y
you can use ViewBag for returning value and access through foreach on view,

Suppose I have a simple records
Id    Name    Status
1     Ram      true
2     Shyam   false

on model

public ABC
{
public int Id{get; set;}
public string Name{get; set;}
public bool Status{get; set;}
}

on Controller

List<ABC> items=new List<ABC>();
items.Add(new ABC{Id=1,Name="Ram",Status=true});
items.Add(new ABC{Id=2,Name="Shyam",Status=false});
ViewBag.dyProp = items;

you should use on view



@foreach(var item in ViewBag.dyProp)
{
if(item.Status)
{
// add approved values
}
}


@foreach(var item in ViewBag.dyProp)
{
if(!(item.Status))
{
// add not approved values
}
}