L
leewestcott
Hi all,
I have datagrid on a C# webform. Users can choose a lookup table to
read\ edit etc via selection from a dropdown list box.
However I cannot figure out the syntax for binding the template columns
to the correct field name at runtime. Below is a code snippet:-
<asp:TemplateColumn HeaderText= "SomeColName">
<ItemTemplate>
<asp:Label runat="server" Text='<%#
Databinder.Eval(Container.DataItem, "ColumnName"))%>
</asp:Label>
</ItemTemplate>
Every single example I have found hard codes the column name as shown
in the example above. However this no good as the user selects the
table at runtime meaning the column names will be different.
I have even tried extracting the column names from the datatable and
placing into a session variable - to no avail. The grid just displays
the column name for every row rather than the contents! i.e
<asp:Label runat="server" Text='<%# Session[varColName] %>
Any Ideas most appreciated.
Lee
I have datagrid on a C# webform. Users can choose a lookup table to
read\ edit etc via selection from a dropdown list box.
However I cannot figure out the syntax for binding the template columns
to the correct field name at runtime. Below is a code snippet:-
<asp:TemplateColumn HeaderText= "SomeColName">
<ItemTemplate>
<asp:Label runat="server" Text='<%#
Databinder.Eval(Container.DataItem, "ColumnName"))%>
</asp:Label>
</ItemTemplate>
Every single example I have found hard codes the column name as shown
in the example above. However this no good as the user selects the
table at runtime meaning the column names will be different.
I have even tried extracting the column names from the datatable and
placing into a session variable - to no avail. The grid just displays
the column name for every row rather than the contents! i.e
<asp:Label runat="server" Text='<%# Session[varColName] %>
Any Ideas most appreciated.
Lee