Reputation: 3945
Using ASP.NET with Dynamic Data my page looks like:
I want to hide the drop-down lists Invoicing Complete
and Restricted Hours
at the top of the page. I have made them invisible from the table by using:
[HideColumnIn(PageTemplate.ListDetails, PageTemplate.List)]
[ReadOnlyColumnIn(PageTemplate.Edit)]
[DisplayName("Invoicing Complete")]
public object Invoicing_Complete { get; set; }
but they are still appearing at the top, as a drop-down.
I can't use [ScaffoldColumn(false)]
as that hides it entirely and I need the user to view it from Edit.aspx
and Insert.aspx
pages.
Please advise.
EDIT: Any one have any ideas? Can't seem to find out how to do this...Did I explain the Q properly?
Upvotes: 3
Views: 1600
Reputation: 806
John, HideColumnIn and ReadOnlyColumnIn are attributes for hide Columns not Filters (ForeignKey filters).
You can solve this problem using a several ways.
The first way, if you are using .NET Framework 4.5 or .NET Framework 4 you may use the AutoGenerateFilter Property of DisplayAttribute. For example,
[Display(Name = "Invoicing Complete", AutoGenerateFilter = false)]
More information you can find on AutoGenerateFilter.
The second way is to create new Attribute (like HideColumnIn) and then change Code-Behind for ForeignKey filter.
Some example:
HideFilterAttribute.cs
using System;
namespace iSite.Classes.Attributes
{
[AttributeUsage(AttributeTargets.Property)]
public class HideFilterAttribute : Attribute
{
public Boolean Hide { get; private set; }
public HideFilterAttribute(Boolean hide)
{
this.Hide = hide;
}
// default
public static HideFilterAttribute Default =
new HideFilterAttribute(false);
}
}
ForeignKey.ascx.cs
public partial class ForeignKeyFilter : System.Web.DynamicData.QueryableFilterUserControl
{
protected void Page_Init(object sender, EventArgs e)
{
string initialValue = DefaultValue;
if (initialValue == null && Column.Attributes.OfType<HideFilterAttribute>().DefaultIfEmpty(HideFilterAttribute.Default).First().Hide)
{
this.NamingContainer.Visible = false;
}
else
{
PopulateListControl(DropDownList1);
if (!String.IsNullOrEmpty(initialValue))
{
ListItem li = new ListItem();
li = DropDownList1.Items.FindByValue(initialValue);
DropDownList1.Items.Clear();
DropDownList1.Items.Add(li);
}
}
}
}
The third and the fourth ways are without DynamicData approach. You can use custom Filter for this column and hide DropDownList control via Visible property. And also you can hide DropDownList control via jQuery library.
Upvotes: 3