0

Ok, so i'm trying to build a website with 2 search fields for the 2 parameters in the following stored procedure and use them to search, i followed an online tutorial i found, the stored procedure is the following:

CREATE PROC Original_Content_Search
@typename VARCHAR(20),
@categoryname VARCHAR(20)
AS
IF @typename is NULL
SELECT *
FROM Original_Content OC INNER JOIN Content C ON  OC.id=C.id
WHERE OC.filter_status=1 and OC.review_status=1 and 
C.category_type=@categoryname
ELSE
SELECT OC.*
FROM Original_Content OC INNER JOIN Content C ON  OC.id=C.id
WHERE OC.filter_status=1 and OC.review_status=1 and C.[type]=@typename

The procedure works as I've tried running it through a query and it worked fine, now I'm trying to use the following based on the tutorial I followed to build a grid from a search but it's just refreshing the page when I click search

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<div>
Search Original Content:
<br />
Search By Type: <asp:TextBox ID="typeSearch" runat="server"></asp:TextBox>
<br />
Search By Category: <asp:TextBox ID="categorySearch" runat="server"></asp:TextBox>
<br />
<asp:Button ID="btnSearch" runat="server" Text="Search" />
<hr />
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
    runat="server" AutoGenerateColumns="false" DataSourceID="GridDataSource" AllowPaging="true">
    <Columns>
        <asp:BoundField DataField="id" HeaderText="ID" ItemStyle-Width="150" />
        <asp:BoundField DataField="content_manager_id" HeaderText="Content Manager ID" ItemStyle-Width="150" />
        <asp:BoundField DataField="reviewer_id" HeaderText="Reviewer ID" ItemStyle-Width="150" />
        <asp:BoundField DataField="review_status" HeaderText="Review Status" ItemStyle-Width="150" />
        <asp:BoundField DataField="filter_status" HeaderText="Filter Status" ItemStyle-Width="150" />
        <asp:BoundField DataField="rating" HeaderText="Rating" ItemStyle-Width="150" />

    </Columns>
</asp:GridView>
<asp:SqlDataSource ID="GridDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConStr %>"
    SelectCommand="Original_Content_Search" SelectCommandType="StoredProcedure">
    <SelectParameters>
        <asp:ControlParameter Name="typename" ControlID="typeSearch" PropertyName="Text" DefaultValue="" ConvertEmptyStringToNull="true" />
        <asp:ControlParameter Name="categoryname" ControlID="categorySearch" PropertyName="Text" DefaultValue="" ConvertEmptyStringToNull="true" />
    </SelectParameters>
</asp:SqlDataSource>
    </div>
</asp:Content>

This as I said only refreshes the page, I'm assuming I need to link the button with the search somehow? or how am I supposed to get this to work? many thanks

Omar Hussein
  • 1,057
  • 2
  • 13
  • 31
  • 1
    That is not a good tutorial to follow. a) doesn't look like MVC. b) is not good to use - your data access should be in your controller or your code behind. – mjwills Dec 05 '18 at 13:01
  • So what do you suggest I follow instead? – Omar Hussein Dec 05 '18 at 13:02
  • Possible duplicate of [Is there a way to call a stored procedure with Dapper?](https://stackoverflow.com/questions/5962117/is-there-a-way-to-call-a-stored-procedure-with-dapper) – mjwills Dec 05 '18 at 13:03
  • 1
    The question is tagged with ASP.NET MVC, but the code shown is WebForms. If you're trying to mix the two, that's probably the cause of your problems. You should really pick one and just use that. – David Dec 05 '18 at 13:03
  • Sorry about that I fixed the tag, I don't really care about how viable this is in a production environment I just need something functional for my assignment so I'm just hoping I can get this webform to work somehow. – Omar Hussein Dec 05 '18 at 13:11
  • @OmarHussein: What does your server-side code look like? What specifically is the code doing in `Page_Load`, in the click handler for `btnSearch`, etc.? – David Dec 05 '18 at 13:23
  • Absolutely Nothing, I followed this tutorial and he doesn't do anything in C# file https://www.aspsnippets.com/Articles/Implement-Search-using-Stored-Procedure-in-ASPNet.aspx – Omar Hussein Dec 05 '18 at 13:26

0 Answers0