locked
ForeignKey_Edit Populating the DropDown with all available values RRS feed

  • Question

  • User-1876416927 posted

    http://forums.asp.net/t/1673340.aspx?Override+PopulateListControl+in+ForeignKey_Edit+field+template

       protected new void PopulateListControl(ListControl listControl)
            {
                var query = Column.Table.GetQuery();
    
                // row
                var entityParam = Expression.Parameter(Column.Table.EntityType, "row");
                // row => row.DataSourceID
                var columnLambda = Expression.Lambda(Expression.Property(entityParam, Column.EntityTypeProperty), entityParam);
                // Items.Select(row => row.DataSourceID)
                var selectCall = Expression.Call(typeof(Queryable), "Select", new Type[] { query.ElementType, columnLambda.Body.Type }, query.Expression, columnLambda);
                // Items.Select(row => row.DataSourceID).Distinct
                var distinctCall = Expression.Call(typeof(Queryable), "Distinct", new Type[] { Column.EntityTypeProperty.PropertyType }, selectCall);
    
                var result = query.Provider.CreateQuery(distinctCall);



    Having used the code from here to populate my dropdown list I find that only values already in the parent table are being displayed in the select list.  I am new to "Expressions" how is it possible to unlink it from the parent table and display all values.  I imagine it's trivial but , as i say, I'm a bear of little brain.

    Monday, August 11, 2014 7:18 AM

All replies

  • User-330204900 posted

    Hi domh, that could be the distinct just omit that and use the CreateQuery using the SelctCall :)

    Monday, August 11, 2014 9:00 AM
  • User-1876416927 posted

    using (var db = new WW1researchDataContext()) { var result = db.GetTable(this.Column.Provider.ColumnType);

    Hi,

    Thank you for replying, I saw it's been a while since you were on this so I am most grateful for you looking at the post.

    Above was the slightly more native way of doing it I discovered, unfortunately the distinct call does what it says on the tin and the link to the parent occurs elsewhere.  I imagine there is something to be done with Column.Table.Provider on the GetQuery front.  Unfortunately the lambda bits look like wizardry to me, I haven't been able to decrypt it!

    Dom

    Monday, August 11, 2014 12:18 PM
  • User-330204900 posted

    Email me direct and we can discuss what you are trying to achieve :)

    Monday, August 11, 2014 12:23 PM