开发者

SubSonic 2.2 and ASP.NET gridview

开发者 https://www.devze.com 2023-01-12 04:02 出处:网络
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

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?开发者_如何学C 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号