locked
DisplayColumn sort is not working RRS feed

  • Question

  • User1432255915 posted

    Hi,

    I am trying to sort the grid display using the Name property but it does not work and the Grid is unsorted. I am using the 3 attributes of DisplayColumn. Any ideas of what is wrong?

     

    namespace BBLDSAccessManager.DAL
    {
        [MetadataType(typeof(PositionMetaData))]
        [DisplayColumn("Name","Name", false)]
        public partial class Position
        {
    
            public class PositionMetaData 
            {
                
                [DisplayName("Position Name")]//shows in the header of grid
                [ScaffoldColumn(true)]
                public object Name { get; set; }
    
    
            }
         }
    }

    Thursday, September 27, 2012 12:47 PM

Answers

  • User-330204900 posted

    Sorry my Bad :( here you go

    [MetadataType(typeof(PositionMetaData))] 
    [DisplayColumn("Name","Name", false)]
    [DisableEditing(true)]
    public partial class Position 
    { 
      internal class PositionMetaData 
      { 
      }
    }  
    

    this should work, not I embed the Metadata/buddy class insed the partial and make it internal so it does not showup anywhere else as we only really need this for the attributes.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 4, 2012 12:35 PM

All replies

  • User1432255915 posted

    Hi,

    Does DisplayColumn only work for foreign keys?

    What I would like to do is sort the grid when the page first load by Name ascending and Name is not a foreign key.

    Please note that I am using Dynamic Data.

    How can I achive that?

    Cheers

    C

    Friday, September 28, 2012 3:56 AM
  • User3866881 posted

    Does DisplayColumn only work for foreign keys?

    Yes, please see:http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.displaycolumnattribute.aspx

    Friday, September 28, 2012 8:45 PM
  • User1432255915 posted

    Hi,

    So how do I sort the grid dynamically when the page List.aspx loads?

    Cheers,

     

    CP

    Saturday, September 29, 2012 6:24 AM
  • User-330204900 posted

    Hi Pallone, see my articel here Setting the Initial Sort Order – Dynamic Data

    Tuesday, October 2, 2012 4:45 AM
  • User1432255915 posted

    Hi Steve,

    Thanks for the link the sort is workin now.

    I am also having a look at another tutorial regarding attributes - "DisableEditingAttribute".

    However, I cannot figure out where in my page to add the code and how to use it.

    Ffor example, in my page load I have added the following code:

    protected void Page_Load(object sender, EventArgs e)
    {
               // Disable Editing
                table = GridDataSource.GetTable();
                Title = table.DisplayName;
    
                 InsertHyperLink.NavigateUrl = table.GetActionPath(PageAction.Insert);
    
                // Disable various options if the table is readonly
                var editingDisabled = table.Attributes.OfType<DisableEditingAttribute>().DefaultIfEmpty(new DisableEditingAttribute()).FirstOrDefault();
                if (table.IsReadOnly || editingDisabled.Disable)
                {
                    GridView1.Columns[0].Visible = false;
                    InsertHyperLink.Visible = false;
                }
    }

    I have also a class called DisableEditingAttribute.cs where I added the code for the attribute as you showed in the article.

    My partial class looks like that at the moment.

    [MetadataType(typeof(PositionMetaData))]
    [DisplayColumn("Name","Name", false)]
    public partial class Position
    {
    }
    
    public class PositionMetaData
    {
    
    }

    Please could you clarify the following:

    1 - Where do I add the DisableEditingAttribute in my partial class

    2 - Could you please clarify if this will disable the link to Edit the entity in the GridView?

    3 - If I want to disable the Delete link instead, could I use the same code?

    Would it be possible for you to put a simple sample together to show how to use your attributes?

    Cheers,

    CP

    Wednesday, October 3, 2012 6:20 AM
  • User-330204900 posted

    Sorry my Bad :( here you go

    [MetadataType(typeof(PositionMetaData))] 
    [DisplayColumn("Name","Name", false)]
    [DisableEditing(true)]
    public partial class Position 
    { 
      internal class PositionMetaData 
      { 
      }
    }  
    

    this should work, not I embed the Metadata/buddy class insed the partial and make it internal so it does not showup anywhere else as we only really need this for the attributes.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 4, 2012 12:35 PM