protected void FilterProducts(object sender, CustomExpressionEventArgs e)
{
switch (int.Parse(Menu1.SelectedValue))
{
case 0 :
e.Query = from p in e.Query.Cast<PRODUIT>()
select p;
break;
case 1 :
e.Query = from p in e.Query.Cast<PRODUIT>()
where p.PRD_ID_CATEGORIE == 1
select p;
break;
case 2:
e.Query = from p in e.Query.Cast<PRODUIT>()
where p.PRD_ID_CATEGORIE == 2
select p;
break;
case 3:
e.Query = from p in e.Query.Cast<PRODUIT>()
where p.PRD_ID_CATEGORIE == 3
select p;
break;
}
}
but nothing happens i mean the filter didn't apply
also i really don't know how to use my "order by" dropdownlist and apply selected sort option
any help is welcome
thanks and good day
ps : i have searched for some tutorials before asking ;)
Please debug by setting the breakpoint at the event I've referred above to see what the value of menu1.SelectedValue is,and then see whether it satisfies the "case" statement……
And then
issam1975
i really don't know how to use my "order by" dropdownlist and apply selected sort option
Just add at the back of query,just like this following:
protected void FilterProducts(object sender, CustomExpressionEventArgs e)
{
switch (int.Parse(Menu1.SelectedValue))
{
case 0 :
e.Query = from p in e.Query.Cast<PRODUIT>()
select p;
break;
case 1 :
e.Query = from p in e.Query.Cast<PRODUIT>()
where p.PRD_ID_CATEGORIE == 1
select p;
break;
case 2:
e.Query = from p in e.Query.Cast<PRODUIT>()
where p.PRD_ID_CATEGORIE == 2
select p;
break;
case 3:
e.Query = from p in e.Query.Cast<PRODUIT>()
where p.PRD_ID_CATEGORIE == 3
select p;
break;
}
e.Query = e.Query.OrderBy(c=>c.SomeColumn).Select(c=>c);
}
issam1975
Member
37 Points
129 Posts
QueryExtender first time use
Jul 28, 2012 01:03 PM|LINK
hi
i only discover the quertyextender component accidentally in my palette this morning :)
it's look cool but have some troubles to use it :
in my page i have :
- a linqdatasource associated to a products database table
- a listview
- a search textbox based on the name product
- a categories menu with theses items (all, categorie1,categorie2,categorie3,... etc)
- a dropdownlist that allow to order by the result with differents options, for example (order by name asc, name desc, price asc, price desc ...etc)
i have added a searchexpression based on the name that work great with the textbox
but for the categories menu and the order by dropdownlist i have some troubles
i have tried to use a CustomExpression like this
<asp:CustomExpression OnQuerying="FilterProducts"></asp:CustomExpression> </asp:QueryExtender>protected void FilterProducts(object sender, CustomExpressionEventArgs e) { switch (int.Parse(Menu1.SelectedValue)) { case 0 : e.Query = from p in e.Query.Cast<PRODUIT>() select p; break; case 1 : e.Query = from p in e.Query.Cast<PRODUIT>() where p.PRD_ID_CATEGORIE == 1 select p; break; case 2: e.Query = from p in e.Query.Cast<PRODUIT>() where p.PRD_ID_CATEGORIE == 2 select p; break; case 3: e.Query = from p in e.Query.Cast<PRODUIT>() where p.PRD_ID_CATEGORIE == 3 select p; break; } }but nothing happens i mean the filter didn't apply
also i really don't know how to use my "order by" dropdownlist and apply selected sort option
any help is welcome
thanks and good day
ps : i have searched for some tutorials before asking ;)
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: QueryExtender first time use
Jul 29, 2012 12:19 PM|LINK
Hi,
Please debug by setting the breakpoint at the event I've referred above to see what the value of menu1.SelectedValue is,and then see whether it satisfies the "case" statement……
And then
Just add at the back of query,just like this following:
protected void FilterProducts(object sender, CustomExpressionEventArgs e) { switch (int.Parse(Menu1.SelectedValue)) { case 0 : e.Query = from p in e.Query.Cast<PRODUIT>() select p; break; case 1 : e.Query = from p in e.Query.Cast<PRODUIT>() where p.PRD_ID_CATEGORIE == 1 select p; break; case 2: e.Query = from p in e.Query.Cast<PRODUIT>() where p.PRD_ID_CATEGORIE == 2 select p; break; case 3: e.Query = from p in e.Query.Cast<PRODUIT>() where p.PRD_ID_CATEGORIE == 3 select p; break; } e.Query = e.Query.OrderBy(c=>c.SomeColumn).Select(c=>c); }