c# - Are SqlDataSource wild cards pageable -
i using visual studio 2010, c#, sqldatasource
. have database of different types of recipes. have encountered problem when use where
clause wildcards.
i can query database , display recipes in pageable , sortable gridview
or listview
if use standard query
select * postedrecipes
the problem happens when use wildcard query such
select recipename postedrecipes recipename '%' + @recipename + '%' group recipename
if database has 100 recipes 30 sandwich recipes, example, , search on "sand" 30 sandwich recipes displayed. if page size set 30, , there 30 sandwich recipes, 30 recipes displayed, not sortable.
the problem not in getting where
wildcards work, rather having results pageable , sortable.
if page size changed 10, 10 sandwich recipes displayed indicator there 2 more pages available. if 2nd or 3rd page clicked, page blank. if "sort" clicked, page returns blank.
using visual studio, not necessary me add code behind above results returned.
i cannot find documentation or literature on particular subject regarding whether possible trying or not - is, have pageable , sortable gridview
or listview
using wildcard, per above. properties of sqldatasource
set dataset
, cache enabled. in right direction appreciated.
edit
this source page - search.aspx
<%@ page language="c#" autoeventwireup="true" codefile="search.aspx.cs" inherits="recipefaire.search" %> <%@ register assembly="ajaxcontroltoolkit" namespace="ajaxcontroltoolkit" tagprefix="asp" %> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="head1" runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:textbox runat="server" id="recipename"></asp:textbox> <asp:button id="button1" runat="server" text="search" postbackurl="~/gridtest3.aspx" /> </div> </form> </body> </html>
search .cs
using system; using system.configuration; using system.data; using system.web; using system.web.security; using system.web.ui; using system.web.ui.htmlcontrols; using system.web.ui.webcontrols; using system.web.ui.webcontrols.webparts; namespace recipefaire { public partial class search : system.web.ui.page { protected void page_load(object sender, eventargs e) { } } }
this sortable , pageable page contains no clause. renders recipes in database - gridtest2.aspx
<%@ page language="c#" autoeventwireup="true" codefile="gridtest2.aspx.cs" inherits="gridtest2" %> <%@ register assembly="ajaxcontroltoolkit" namespace="ajaxcontroltoolkit" tagprefix="asp" %> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:sqldatasource id="sqldatasource1" runat="server" connectionstring="<%$ connectionstrings:recipeuploadconnectionstring %>" selectcommand="select [recipeid], [recipename], [description] [postedrecipes]"> </asp:sqldatasource> <asp:gridview id="gridview1" runat="server" allowpaging="true" allowsorting="true" autogeneratecolumns="false" datakeynames="recipeid" datasourceid="sqldatasource1"> <columns> <asp:boundfield datafield="recipeid" headertext="recipeid" insertvisible="false" readonly="true" sortexpression="recipeid"></asp:boundfield> <asp:boundfield datafield="recipename" headertext="recipename" sortexpression="recipename"> </asp:boundfield> <asp:boundfield datafield="description" headertext="description" sortexpression="description"> </asp:boundfield> </columns> </asp:gridview> </div> </form> </body> </html>
code behind gridtest2 generated visual studio - gridview.cs
using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; public partial class gridtest2 : system.web.ui.page { protected void page_load(object sender, eventargs e) { } }
code page clause. page renders searched term recipes not page or sort - gridtest3.aspx
<%@ page language="c#" autoeventwireup="true" codefile="gridtest3.aspx.cs" inherits="gridtest" %> <%@ register assembly="ajaxcontroltoolkit" namespace="ajaxcontroltoolkit" tagprefix="asp" %> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:sqldatasource id="sqldatasource2" runat="server" connectionstring="<%$ connectionstrings:recipeuploadconnectionstring %>" selectcommand="select [recipeid], [recipename], [description] [postedrecipes] ([recipename] '%' + @recipename + '%') group recipeid, recipename, description order recipeid, recipename, description"> <selectparameters> <asp:formparameter formfield="recipename" name="recipename" type="string" /> </selectparameters> </asp:sqldatasource> <asp:gridview id="gridview2" runat="server" allowpaging="true" allowsorting="true" autogeneratecolumns="false" datasourceid="sqldatasource2"> <columns> <asp:boundfield datafield="recipename" headertext="recipename" sortexpression="recipename"></asp:boundfield> <asp:boundfield datafield="description" headertext="description" sortexpression="description"></asp:boundfield> </columns> </asp:gridview> </div> </form> </body> </html>
code behind gridtest3.aspx generated visual studio - gridtest3
using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; public partial class gridtest3 : system.web.ui.page { protected void page_load(object sender, eventargs e) { } }
Comments
Post a Comment