Question about DataBinder.Eval method

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with a DataList control with a label control and a text control
in the ItemTemplate section. I can display the data in the text contol using
the DataBinder.Eval method and I also want to display the Field or the Column
title in the Label control.

How can I retrieve the column (field) name from the Container?

TIA
 
Pierre:
Not sure I understand...

you have this:

<asp:label id="field" runat="server"> </asp:label> : <asp:textbox id="value"
runat="server" text='<%=DataBinder.Eval(Container.DataItem, "FirstName")%>'
/>

From what I understand you want to display "FirstName" in the label...why
not simply type in "FirstName" ...clearly you know what the column name is
because you are using it in the text control....

Karl
 
Karl:
I wanted to change the label's text dynamically from code. Does the DataItem
has a property that holds the field name?

Pierre
 
Pierre,
Yes and no...if you are binding to a DataSet, DataTable or DataView,
Container.DataItem is actually of type DataRowView, from which you can get
the underlying DataTable. The DataTable does indeed know the column names,
but not sure how you figure out which column you want.

ctype(Container.DataItem,
System.Data.DataRowView).DataView.Table.Columns(0).ColumnName but not
sure how you figure out that you want column 0

That's all I can think of...
Karl
 
Karl:

Good question Regarding knowing which field to choose. The data comes from a
stored procedure and I could select the fields in proper order and use the
column index to address the columns.

the info on ItemData was very useful.
Thank you

Pierre
 
Back
Top