Posts

Showing posts from February, 2008

Bad programmer, Bad!

Ok so I posted some javascript for a numeric only textbox and it wasn't working. Someone posted a comment about it so I took a look at it. Sure enough the whole thing was boned. Hopefully I didn't lead anyone astray or anything. So I fixed the script and tested it and found it works now. So if anyone wants to read the new script it's over here:

JavaScript post

Saving Changes to a DataTable bound to a DataGridView

Ok,

So I'm working on app that binds a datatable to a data grid view. Normally you would just edit right in the grid and be done. However our table has too much data to edit right in the grid so instead users have to click a row on the grid to load a details panel below the grid. This works great except I noticed changes made to the last row weren't being saved. This is because the grids don't commit changes to their datasource unless a new row is clicked. So after a few hours of digging I found this bit of code worked very well.

// commit all our changes to the datasource of our gridif( dataGridViewVariables.BindingContext[_tableEditVariables] != null ){  dataGridViewVariables.BindingContext[_tableEditVariables].EndCurrentEdit();}//end if
Check that the object in this case a data table being used to bind exists. And if it does call the end current edit on that object. However if you're binding to a custom collection of objects I believe you need to implement a c…

Firefox 3 Beta 3 is in the wild

Ok so Firefox v3 has release a new beta version 3. I have downloaded it and will see if the memory issues are still improving.

Download here

Using the ItemDataBound event with a DataReader vs DataTable/DataView

A little while back I was blogging about how we were switching over to datareaders for getting data back from our database. Well it was working fine until we noticed on some of our pages data wasn't being calculated correctly. This was traced to the ItemDataBound event used in our grids/repeaters not working correctly. With a datatable/view we would cast the e.Item.DataItem as a DataRowView; which works just fine. However datareaders when being databound can't be cast as DataRowViews. You have to use the DbDataRecord class. Afte switching from the DataRowView to DbDataRecord in the ItemDataBound event everything works just like it should. DbDataRecord is in the System.Data.Common namespace. Make sure you are importing that namespace if you haven't already.

So to summarize it:


Binding ObjectWhat to Cast to in ItemDataBound event

DataReaderDbDataRecord

DataTableDataRowView

DataViewDataRowView