views:

18

answers:

1

Hi all,

I'm trying to show a custom column in my gridview which displays a content type based on a couple of boolean fields in my database. Everything works fine but it's causing a lot of overhead the way I do it now.. like this:

<ItemTemplate>
   <asp:Label ID="lblType" runat="server" Text='<%# GetType((int)DataBinder.Eval(Container.DataItem))%>' />
</ItemTemplate>

This calls a function GetType which queries the database based on the ArticleID. Of course this happens for every item in the gridview. Now I would like to know if it's possible to send the current (subsonic) collection item to this function instead? Because the item is already available but I don't know how to put this in my itemtemplate.

My current item is DAL.Article which contains everything I need.

I hope I made myself clear a little !Thanks for your time.

Kind regards, Mark

A: 

Subsonic generated classes are partial and thus extendable. Let's say you have a DAL object called Person. You can create a new file Person.cs (in a different folder of course).

namespace Your.Dal.Namespace {
    public partial class Person
    {
        public string DisplayName
        {
            get
            {
                return String.Format("{0}, {1}", this.LastName, this.FirstName);
            }
        }
    }
}

Now you can access the DisplayName property of your class:

PersonCollection col = new PersonCollection().Load();

foreach(Person p in col)
    Console.WriteLine(p.DisplayName);

I use this technique for binding Subsonic Collections to a Windows.Forms DataGridView a lot. But it should work for asp.net, too.

SchlaWiener
Perfect solution friend haven't even thought of that. Thank you very much!
Mark