|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Set column names to template grid at runtimeI 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 Hi Lee,
Try datagrid.Columns[index].HeaderText = ColumnName; in codebehind. HTH, Elton Wang elton_w***@hotmail.com >-----Original Message----- lookup table to>Hi all, > >I have datagrid on a C# webform. Users can choose a Show quoteHide quote >read\ edit etc via selection from a dropdown list box. name as shown> >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 Show quoteHide quote >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 > >. >
Datagrid ... pain .... HELP!
Problem with datagrid update CancelCommand Not Firing! problem updating in datagrid ?? How to refresh a parent grid? Hyperlink Column Event Handler... Dynamically adding DataGrid columns Datagrid Footer now showing up correctly datagrid(master) with a datalist(detail) selection of fields in datatable for Datagrid |
|||||||||||||||||||||||