November 2010
1 post
6 tags
This row already belongs to another table
It does, that’s the whole point - I’m trying to copy a row from one datatable to another.
Funnily, we can’t just use the (dt is DataTable) “dt.Rows.Add(<datarow>)” method; probably because the datarow contains identifying information relevant to the original datatable - so we have to use “dt.ImportRow(<datarow>)” instead.
Just remember that...
August 2010
2 posts
5 tags
One of the most elementary mistakes that I have seen fellow coders make, in .NET anyway, is trying to loop through data within objects using a count of rows/columns. The row number of the datarows does not start at the same number as the start of the loop through a reflection of .Count.
If you are looping through a set of datarows it will start at 0, as objects are zero-based indexed.
If you...
4 tags
Here’s some delightful error handling…
Catch oor As ArgumentOutOfRangeException
‘Try going back one? *shrug*
i = i -1
Yup, if the loop has gone too far but still has stuff to process, just … go back and do the last one again :)
July 2010
3 posts
9 tags
My favourite mistake, databinding too early.
If there is one mistake I make almost every single time when working with webforms it is this one, databinding controls during the OnLoad event. This is particularly perilous for DropDownLists and RadioButtonLists and I’ll tell you why …
OnLoad is fired very early on in the ASP.NET page lifecycle and what this does is wipe out any selections you made before postback because the...
5 tags
Injecting Javascript into webforms from...
AJAX has become very very popular and the resurgence of javascript has been unprecendented, spurred on by libraries like jQuery and Mootools, we can now do partial-page postbacks, get data and fire events asynchronously easier than ever thought possible.
In ASP.NET we have the luxury of having an AJAX framework built in from v3.5 onwards that includes some pretty powerful tools, the best of which...
4 tags
Viewstate is your friend
Persisting the state of DropDownLists in ASP.NET is simpler than you think. A lot of people will go the way of storing the SelectedIndex in a Session variable on postback then retrieving it and setting the SelectedIndex again on Load - but this is all unnecessary in most circumstances.
If you simply want to set the SelectedValue to be what it was before a PostBack, simply use the EnableViewState...