动态数据母版页过滤 [英] Dynamic Data Master Page Filtering

查看:110
本文介绍了动态数据母版页过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET 4动态数据Linq网站,我希望有一个可在母版页上设置的过滤器,然后由动态数据自定义页拾取该过滤器,并使用该过滤器来过滤其数据.

我正在学习,所以如果我做了一些不是最佳实践或愚蠢的事情...

在我的母版页上,我有用于过滤器的组合框,并且在其背后的代码中:

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;
    ...
}



因此,我现在可以引用需要过滤的值.我想!

我尝试在Page_Init和GridDataSource OnSelecting事件期间使用GridDataSource的where子句.但是我的变量为空,或者代码没有触发.



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.

推荐答案

要应用该过滤器,我在LinqDataSource中添加了以下内容:
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>



其中ControlID是母版页上控件的ID.

这样会在回发后进行过滤...这有点丑陋,所以可能会有更好的方法.



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.


尝试一下:

Try this:

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



然后,您应该能够获得选定的索引.



And then you should be able to get the selected index.


这篇关于动态数据母版页过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆