ASP.net bind datatable columns to gridview template columns dyamically

Murray Brown
Murray Brown used Ask the Experts™
on
Hi. I have an ASP.net GridView that has several template columns like that shown below. A datatable is bound to the GridView
but sometimes one or two of the columns that the template fields bind to are not included in the datatable.
So if the "EmployeeName" column is not in the datatable  there will be an error. The only way that I can think of doing this
is to assign each datatable column to the corresponding gridview template column programatically but I am not sure how to do this

    <asp:TemplateField HeaderText="Employee Name" Visible="true">
                           <ItemTemplate>
                                <asp:Label ID="lblEmployeeName" runat="server" Text='<%# Bind("EmployeeName")%>' Visible="true"></asp:Label>
                           </ItemTemplate>
                      </asp:TemplateField>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Developer User Interface
Commented:
You may want to dynamically add the template columns to the gridview.

Gridview Dynamic template columns
Murray BrownASP.net/VSTO Developer

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial