Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more: , +
I have Search Panel with TextBox and Two DropDownList (txtKeyword, ddlCategory, ddlProvider), i want search with one of them or two together or all, so i used COALESCE Statement..

(
	@Course NVARCHAR(200) = NULL,
	@Category NVARCHAR(50) = NULL,
	@Provider NVARCHAR(200) = NULL	
)
AS
BEGIN
SELECT Course.CourseId, Course.CourseName, Course.CourseDescription, 
       Course.CourseHours, Category.CategoryName, Provider.ProviderName, 
       CourseType.CourseTypeName
FROM Course INNER JOIN
     Category ON Course.CategoryId = Category.CategoryId INNER JOIN
     Provider ON Course.ProviderId = Provider.ProviderId INNER JOIN
     CourseType ON Course.CourseTypeId = CourseType.CourseTypeId
WHERE (Course.CourseName = COALESCE (@Course, Course.CourseName)) AND
      (Category.CategoryName = COALESCE (@Category, Category.CategoryName)) AND
      (Provider.ProviderName = COALESCE (@Provider, Provider.ProviderName))

END	


-------------------------------------------------------
Then used it with SqlDataSource and GridView

XML
<asp:GridView ID="gvUserSearch" runat="server" DataKeyNames="CourseID"
        Width="100%" AllowPaging="True" EnableViewState="False"
        AutoGenerateColumns="False">


    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />

    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <Columns>
            <asp:BoundField DataField="CourseID" HeaderText="Course ID" />
            <asp:BoundField DataField="CourseName" HeaderText="Name" />
            <asp:BoundField DataField="CourseDescription" HeaderText="Description" />
            <asp:BoundField DataField="CourseHours" HeaderText="Hours" />
            <asp:BoundField DataField="CategoryName" HeaderText="Category" />
            <asp:BoundField DataField="ProviderName" HeaderText="Provider" />
            <asp:BoundField DataField="CourseTypeName" HeaderText="Course Type" />
        </Columns>
    <EditRowStyle BackColor="#999999" />
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />

    </asp:GridView>


    <asp:SqlDataSource ID="dsCourses" runat="server"
            ConnectionString="<%$ ConnectionStrings:ShareCon %>" SelectCommand="sp_GetAllCourses"
            SelectCommandType="StoredProcedure">


    <SelectParameters>
        <asp:QueryStringParameter ConvertEmptyStringToNull="true" Name="Course"
        Type="String" QueryStringField="CourseName" />
        <asp:QueryStringParameter ConvertEmptyStringToNull="true" Name="Category"
        Type="String" QueryStringField="Category" />
        <asp:QueryStringParameter ConvertEmptyStringToNull="true" Name="Provider"
        Type="String" QueryStringField="Provider" />
    </SelectParameters>

</asp:SqlDataSource>


--First-- in Main Page that contains (TextBox and DropDownLists only) (there's six states this one of them)
C#
Response.Redirect("SearchResults/Default.aspx?CourseName=" +
                    "&Category=" + "&Provider=");


i tried this too..
C#
Response.Redirect("SearchResults/Default.aspx?CourseName=NULL" +
                    "&Category=NULL" + "&Provider=NULL");


--nd-- in Default.aspx

C#
gvUserSearch.DataSourceID = "dsCourses";
gvUserSearch.DataBind();
Posted
Updated 26-Apr-11 5:08am
v2

1 solution

hi,

try or instead of and in sproc
 
Share this answer
 
Comments
SerpentKiss2010 27-Apr-11 9:17am    
Sorry sir, actually i don't understand ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900