Datagrid binding to the wrong value

D

DCC700

I have a datagrid that appears to be binding to the wrong value of the
data table being bound. The datagrid is in a user control that is used
multiple times on the page. The other instances are binding as expected.
I am binding to a datatable that I create in code and when debugging I
can see the correct values are in the datatable, and to the datagrid
source after I assign the datatable to it. But after calling DataBind
the corresponding values in the cells of the data grid are not correct.
Here is a sample of how the code looks.

dt = CreateDataTableforDG()

dgData.DataSource = dt

dgData.DataBind()

I have checked that the values are assigned to the columns with the same
name as the datafield in the columns of the datagrid. The columns are
not in the same order, but that shouldn't matter. Here is a sample of
how the data looks.

Col0 Col1 Col2 Col3
DataTable Descr1 .5 0 1
DGDataSource Descr1 .5 0 1
DataGrid Descr1 1 1

It appears like Col3 is getting the right value and possibly column 1 is
getting the value from column3. This is very weird. It seems like I'm
missing something but haven't been able to find it.

Has anyone encountered anything like this?

Does anyone have any suggestions?
 
D

DCC700

Okay I am a moron. I have found that the values are not displaying
correctly due to the data format defined for the column.

The other data grids are all displaying whole numbers, so they show
fine, but this one needs to show decimal values. Thus the 1 is really
the .5 rounded up.

Now I am trying to find how to update the data format of the column at
runtime. Whatever event I try to update this in (Load, ItemCreated,
ItemDataBound) it is keeping the original format.

Any suggestions here?
 
D

DCC700

I have the formatting working now. I needed to update the grid format
before binding the datagrid instead of trying to do this on one of the
datagrid events.

Hope this helps someone else down the road.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top