Click here to Skip to main content
15,607,633 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I've got a ASP.NET 4 Dynamic Data Linq site, and I would like to have a filter that is settable on the master page, which the Dynamic Data custom pages then pick up, and use to filter their data.

I'm learning this, so if I've done something that's not best practise or just stupid...

On my master page I've got my combo box for the filter and in the code-behind:
public int pagePromoID;
public string pageApprovalID;

protected void promoIDs_SelectedIndexChanged(object sender, EventArgs e)
    //store the selected promotion in the master page variables
    pagePromoID = int.Parse(promoIDs.SelectedValue);
    pageApprovalID = promoIDs.SelectedItem.Text;

Then in my Custom Dynamic Page (based on the List pre-built one):
protected Site site;
protected void Page_Init(object sender, EventArgs e)
    site = (Site) this.Master;

So I can now reference the value I need to filter on. I think!

I've tried using the where clause of the GridDataSource during Page_Init and the GridDataSource OnSelecting event. But either my variables are empty, or the code doesn't fire.

To get the filter to apply, I added the following to the LinqDataSource:
<whereparameters><asp:ControlParameter name="PromoID" defaultvalue="0" type="Int32" controlid="promoIDs" /></whereparameters>

Where the ControlID is the id of the control on the master page.

This filters after a post back...which is a bit ugly, so there might be a better way.
Share this answer
Try this:

ControlType control = (ControlType)Master.FindControl("controlID");

And then you should be able to get the selected index.
Share this answer
cjb110 29-Mar-11 9:44am    
Ok, just tried that, and the index always seems to be -1? I put the code in the page_init of my custom page. On debug it does look like its referenced the right control.

I think some of the problem is my misunderstanding of how the master and custom page are combined, and how/when the varing events are fired...its a lot less clear than winforms!

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