bind datatable columns to gridview template columns dyamically

Murray Brown
Murray Brown used Ask the Experts™
Hi. I have an 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">
                                <asp:Label ID="lblEmployeeName" runat="server" Text='<%# Bind("EmployeeName")%>' Visible="true"></asp:Label>

Open in new window

Watch Question

Do more with

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

Gridview Dynamic template columns
Murray Developer



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