I have DataTable with tow columns (id,fname) and a WebDataGrid, the code for filling the datatable and the datagrid is:
Dim dd As New test
Dim dt4 As DataTable = dd.DataTable1
WebDataGrid1.DataSource = dt4
everything is working fine, but when I add a BoundDataField with a key named (fname) same as the column's name in the datatable to set some behaviors to the column, so the Asp.net code is:
<ig:WebDataGrid ID="WebDataGrid1" runat="server" Height="350px" Width="400px" ><Columns> <ig:BoundDataField DataFieldName="fname" Key="fname"> <Header Text="fname"> </Header> </ig:BoundDataField> </Columns> </ig:WebDataGrid>
so, the DataGrid suppose to bound the BoundDataField into the DataTableColumn which is (fname), but why now I'm getting 2 columns in datagrid? the results I get is:
Please set autoGenerateColumns property of the grid to false.
By default its value is true, which means the grid is generating a column for each datasource field(so it has generated an id and fname columns), then later you add one more column with the same name through the markup.
If you set it to false, you need to add the id column by markup or code by yourself. Or just leave the grid to autogenerate the columns for you.
Generally you choose to autogenerate the columns if you dont know what data is coming from the datasource, otherwise you configure the columns by yourself in markup or in code. This gives you way more flexibility over configuring all properties of the columns.
I set it to False, but now I'm only getting the DataBoundFiled "fname", not the ID column, shall I have to add DataBoundField "id"? I have many other columns in the DataTable not only these two, more than 10 columns.
You can just leave as it is now and remove the fname column from the markup to prevent having two fname columns.