禁用动态数据列表视图上的过滤

发布于 2024-09-14 13:50:28 字数 479 浏览 1 评论 0原文

我有一组 NotificationTemplate 实体,其中每个实体都有一组零多个 SmsTemplate 实体。编辑或查看NotificationTemplate时,我有一个指向查看短信模板的链接。该链接将我带到 SmsTemplates 实体集的列表视图,并针对我正在查看的 NotificationTemplate 进行筛选。

如何防止用户更改此过滤器以显示另一个 NotificationTemplateSmsTemplates?也就是说,我想要过滤器,但它必须是只读的。下拉菜单不能下拉,它必须只显示这些 SmsTemplate 所属的 NotificationTemplate 的名称。要查看另一个NotificationTemplate 的SmsTemplates,用户必须从该其他模板中单击查看SMS 模板

I have an entity set of NotificationTemplates, and each one of these has a collection of zero-many SmsTemplate entities. When editing or viewing a NotificationTemplate, I have a link to View SMS Templates. That link takes me to a List view for the SmsTemplates entity set, filtered for the NotificationTemplate I was viewing.

How can I prevent the user changing this filter to show SmsTemplates for another NotificationTemplate? That is, I want the filter, but it must be read only. The drop-down just mustn't drop down, it must just display the name of the NotificationTemplate that these SmsTemplates belong to. To view SmsTemplates for another NotificationTemplate, the user must click View SMS Templates from that other template.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜雨飘雪 2024-09-21 13:50:28

过滤器模板的代码隐藏告诉过滤器从查询字符串中获取其值。它检查 DefaultValue 属性,并且如果设置为一个值,则将其分配给过滤器。您想要做的是添加逻辑,使过滤器在 DefaultValue 有值时变为只读。使其只读的最简单方法是禁用该控件。以下是默认 ForeignKey.ascx.cs 实现的操作方法:

protected void Page_Init(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        if (!Column.IsRequired)
        {
            DropDownList1.Items.Add(new ListItem("[Not Set]", NullValueString));
        }
        PopulateListControl(DropDownList1);
        // Set the initial value if there is one
        string initialValue = DefaultValue;
        if (!String.IsNullOrEmpty(initialValue))
        {
            DropDownList1.SelectedValue = initialValue;
            DropDownList1.Enabled = false;
        }
    }
}

The code-behind of the filter template is what tells the filter to pick up its value from the query string. It checks the DefaultValue property, and if set to a value, assigns that to the filter. What you want to do is add logic that makes the filter read-only when DefaultValue has a value . The simplest way to make it read-only this is to make the control disabled. Here's how you would do it for the default ForeignKey.ascx.cs implementation:

protected void Page_Init(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        if (!Column.IsRequired)
        {
            DropDownList1.Items.Add(new ListItem("[Not Set]", NullValueString));
        }
        PopulateListControl(DropDownList1);
        // Set the initial value if there is one
        string initialValue = DefaultValue;
        if (!String.IsNullOrEmpty(initialValue))
        {
            DropDownList1.SelectedValue = initialValue;
            DropDownList1.Enabled = false;
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文