Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

Datagrid binding to the wrong value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DCC700 - 13 Sep 2007 17:23 GMT
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?
DCC700 - 13 Sep 2007 18:32 GMT
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?
DCC700 - 13 Sep 2007 19:23 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.