Answered by:
ASP.NET: How to add a new column in a Datagrid.

Question
-
User-1953438450 posted
Hello All,
I am a newbie in ASP.NET. I need to add a new column in a Datagrid on my .ascx file.
I have tried in adding a new column definition in this way
<asp:BoundColumn DataField="NewField" HeaderText="NewField"></asp:BoundColumn>
The DataGrid definition is the following
<asp:datagrid id="dgListFields" runat="server" CssClass="dataGridBody" Width="768px" AutoGenerateColumns="False"
CellSpacing="1" CaptionAlign="Left" AllowPaging="True" PageSize="10000" AllowSorting="True">
After pressing F5 and after the login to view my new web page I receive this error message
A field or property with the name 'NewField' was not found on the selected data source.
Error on Bind in my DataGrid.
Is it necessary to process some new step?
Any help will be greatly appreciated.
Thanks in advance for your kind support.
Regards,
Giovanni
Monday, October 10, 2016 4:26 PM
Answers
-
User-654786183 posted
<asp:BoundColumn DataField="NewField" HeaderText="NewField"></asp:BoundColumn>The property "DataField" needs to have a matching column in the datasource you are using to bind the grid. If you don't have "Newfield" column in your datasource, try getting the value or change the column name to "Newfield" in your datasource
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, October 10, 2016 5:38 PM -
User-1716253493 posted
If you want add BoundField, ensure datafield value matching with the query
SELECT NewField, ....
Or you can add templatefield column to the grid
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, October 10, 2016 6:03 PM
All replies
-
User-654786183 posted
<asp:BoundColumn DataField="NewField" HeaderText="NewField"></asp:BoundColumn>The property "DataField" needs to have a matching column in the datasource you are using to bind the grid. If you don't have "Newfield" column in your datasource, try getting the value or change the column name to "Newfield" in your datasource
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, October 10, 2016 5:38 PM -
User-1716253493 posted
If you want add BoundField, ensure datafield value matching with the query
SELECT NewField, ....
Or you can add templatefield column to the grid
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, October 10, 2016 6:03 PM