How do I get TypedList column name at run-time

Posts   
 
    
Posts: 30
Joined: 21-Apr-2005
# Posted on: 10-Jun-2007 00:04:56   

In ASP.NET I am able to use the following code to get the column name of an entity at runtime: <td style="width: 10%;"> <%#Eval(TransitionDL.HelperClasses.MyEntityFields.id.Name%> </td>

How can I do something similar to get the column name used in a Typed List where the column name is different than the underlying table's column name?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-Jun-2007 05:25:53   

Hi John, have you tried

#Eval(MyDynamicList.Columns[0].ColumnName)

??

David Elizondo | LLBLGen Support Team
Posts: 30
Joined: 21-Apr-2005
# Posted on: 11-Jun-2007 10:11:29   

Eval(MyDynamicList.Columns[0].ColumnName) may work, but that defeats the point of my using it. It forces me to track column indexes and is not very descriptive in the code.

Does this make sense?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Jun-2007 10:52:16   

To access a column inside the columns list, you have to use the indexer or the columnName, which won't make sense since you need to display the column name.

Since TypedLists are actually views on some Entities, you can use the corresponding EntityField.Name solution as you did with the entities, provided that you haven't changed the ColumnName in the TypedList.

Posts: 30
Joined: 21-Apr-2005
# Posted on: 12-Jun-2007 23:56:31   

Is there any reason why Typed Lists do not have EntityField.Name paradigm like entities do? I needed to rename the fields in the typed list because we are creating a typed list that pulls from the same entity several times.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Jun-2007 08:54:01   

You can find an enum in the constantEnums.cs which holds the field indexes of the TypedList it should be called _YourTypedListName_FieldIndex.

I needed to rename the fields in the typed list because we are creating a typed list that pulls from the same entity several times.

I didn't understand this part, would you please elaborate?

Posts: 30
Joined: 21-Apr-2005
# Posted on: 13-Jun-2007 19:33:38   

I didn't understand this part, would you please elaborate?

For example, I have 2 tables called 'Product' and 'Codes'. The 'Product' table has several columns that reference the 'Code's table with a foriegn key. I need to display the description field in the Code table. When I create the typed list in LLBL designer, the fields will be named 'description', '_description', and '__description' by default. So I rename them to make sense.

In my aspx page I want to avoid using Eval("myColumnName") inside of a repeater control because I type poorly and will make a mistake from time to time. If I was binding to a collection I could use

<%#Eval(MyDataLayer.HelperClasses.MyEntityFields.MyColumn.Name) %>

I was looking for a similar solution for typed lists. Here is the solution that I came up with that works for me

<%#CType(CType(Container.DataItem, Data.DataRowView).Row, MyDataLayer.TypedListClasses.MyTypedListRow).MyColumn%>