• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

How do I call a class from an asp.net data source's control event?

I have written a C# web site using visual studio 2008. I am using an asp.net 3.5 listview control to display my data. I have written the attached classes within my project where I am now looking to call the "public partial class Trust" within the OnSelecting event of my linqdatasource which is bound to my listview control. Can anyone give me some help on how to do this?

Thanks.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
 
/// <summary>
/// Summary description for LinqPredicateBuilder
/// </summary>
public static class LinqPredicateBuilder
{
    public static Expression<Func<T, bool>> True<T>() { return f => true; }
    public static Expression<Func<T, bool>> False<T>() { return f => false; }
 
    public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expr1,
                                                        Expression<Func<T, bool>> expr2)
    {
        var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
        return Expression.Lambda<Func<T, bool>>
              (Expression.OrElse(expr1.Body, invokedExpr), expr1.Parameters);
    }
 
    public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> expr1,
                                                         Expression<Func<T, bool>> expr2)
    {
        var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
        return Expression.Lambda<Func<T, bool>>
              (Expression.AndAlso(expr1.Body, invokedExpr), expr1.Parameters);
    }
}
 
public partial class Trust
{
    public static Expression<Func<Trust, bool>> ContainsInDescription(params string[] keywords)
    {
        TrustSystemMARTINSPALDINGDataContext db = new TrustSystemMARTINSPALDINGDataContext();
        
        var predicate = LinqPredicateBuilder.True<Trust>();
        foreach (string keyword in keywords)
        {
            string temp = keyword;
            predicate = predicate.Or(p => p._ClientName.Contains(temp));
            predicate = predicate.Or(p => p._MatterNo.Contains(temp));
            predicate = predicate.Or(p => p._PartnerLookup.Entity.PartnerDescription.Contains(temp));
            predicate = predicate.Or(p => p._FeeExecLookup.Entity.FeeExecDescription.Contains(temp));
            predicate = predicate.Or(p => p._TypeLookup.Entity.TypeDescription.Contains(temp));
 
            var query = (from tt in db.Trusts.Where(predicate)
                         join felt in db.FeeExecLookups on tt.FeeExecCode equals felt.FeeExecCode
                         join ilt in db.IncomeLookups on tt.IncomeCode equals ilt.IncomeCode
                         join plt in db.PartnerLookups on tt.PartnerCode equals plt.PartnerCode
                         join tlt in db.TypeLookups on tt.TypeCode equals tlt.TypeCode
                         // perform a left join on TrustTypeLookups so all fields are returned including NULLs
                         join ttlt in db.TrustTypeLookups on tt.TrustTypeCode equals ttlt.TrustTypeCode into tc
                         from ttlt in tc.DefaultIfEmpty()
                         orderby tt.ClientName ascending
                         // TrustTypeDescription is selected on different cases below: whether it's null, nothing or something
                         select new { tt.TrustID, tt.ClientName, tt.MatterNo, tt.PartnerCode, tt.FeeExecCode, tt.TypeCode, tt.TrustTypeCode, tt.Nominee, tt.TEA, tt.IncomeCode, tt.TrustNotes, tt.Archive, felt.FeeExecDescription, ilt.IncomeDescription, plt.PartnerDescription, tlt.TypeDescription, TrustTypeDescription = ttlt.TrustTypeDescription == null ? "" : ttlt.TrustTypeDescription });
        }
        return predicate;
    }
}

Open in new window

0
Shepwedd
Asked:
Shepwedd
1 Solution
 
Christian de BellefeuilleProgrammerCommented:
I'm not a c# programmer (i program in VB.NET & ASP.NET usually).  But when you want to link that to a listbox, usually your class must inherits from a datasource object like SQLDataSource and you must implements every function needed to extract the data...

I see no such thing in your code.

Once you have done this, just set the DataSourceID of your listbox to an instance of your class.
0
 
ShepweddAuthor Commented:
My problem was resolved by moving the code within my "public partial class trust" to my "OnSelecting" event of my linqdatasource. I guess I miss understood my class code.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now