c# - Setting where clause and parameters of linqdatasource like a Linq query -


i have listview , binding in codebehind linq query selects related keywords

mydatacontext dcxt = new mydatacontext(); string x = "searchword"; // x user var query = ak in dcxt.wordindexes             ak.word == x             in ak.keywords             a.comps.approved &&             a.comps.active &&             a.approved              orderby a.etbm descending             select a;  listview1.datasource = query; listview1.databind(); 

i have one-to-many relationship between wordindexes -> keywords, one-to-many between comps -> keyswords.

now want use linqdatasource, can let linqdatasource handle paging. cant set clause linq query.

<asp:linqdatasource id="lds2" runat="server"      contexttypename="mydatacontext" entitytypename=""      orderby="" tablename="keywords"     where=""> </asp:linqdatasource> 

i tried use datapager (without linqdatasource) paging slow if results hold alot of items. used linqdatasource before simpler queries, little complex me because of relationships between tables , dont know start building clause. help?

update:

i ended using linqdatasourceselectevent datapager suggested in answer

protected void linqds_selecting(object sender, linqdatasourceselecteventargs e) {     var query = ak in dcxt.wordindexes                 ak.word == x                 in ak.keywords                 a.comps.approved &&                 a.comps.active &&                 a.approved                  orderby a.etbm descending                 select a;      e.arguments.totalrowcount = query.count();     e.result = query.skip(datapager1.startrowindex).take(datapager1.pagesize); } 

you can use linqdatasource_selecting event , passing query to


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -