Skip to content

WebDataGrid with BoundDataField

New Discussion
Osama Gadour
Osama Gadour asked on Nov 21, 2019 9:21 AM

Dears

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
        dt4.Rows.Add("1", "TestName")
        dt4.Rows.Add("2", "TestName2")
        WebDataGrid1.DataSource = dt4
        WebDataGrid1.DataBind()

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:

Sign In to post a reply

Replies

  • 0
    Hristo Anastasov
    Hristo Anastasov answered on Nov 21, 2019 9:13 AM

    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.

    • 0
      Osama Gadour
      Osama Gadour answered on Nov 21, 2019 9:18 AM

      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.

      • 0
        Hristo Anastasov
        Hristo Anastasov answered on Nov 21, 2019 9:21 AM

        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.

        You can just leave as it is now and remove the fname column from the markup to prevent having two fname columns.

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Osama Gadour
Favorites
0
Replies
3
Created On
Nov 21, 2019
Last Post
6 years, 3 months ago

Suggested Discussions

Created by

Created on

Nov 21, 2019 9:21 AM

Last activity on

Nov 21, 2019 9:21 AM