Tuesday, July 17, 2007

erroneous InvalidCastException


todays puzzler may be hard to read in the screen shot above (click on image to expand) but basically the debugger is complaining that I'm trying to cast the value "0" to an integer value and it can't handle that. (fwiw, most people accept zero as a valid integer)... bizarre!

if ((int)Args.NewValues["ItemPrice"] < 0)
{
Args.Cancel = true;
EditMSG.Text = "-- Item price is out of range";
}

can anyone tell me why the if statement bombs when Args.NewValues["ItemPrice"] == "0"? I should think that would cast nicely to an int as I am attempting. (BTW Args is type DetailsViewUpdateEventArgs)

UPDATE:
here's a workaround --
if (Convert.ToInt32(Args.NewValues["ItemPrice"]) < 0)...

this way you're not casting, you're converting. ok!

Wednesday, July 11, 2007

asp.net debugging annoyance...

so I run my app and notice at the bottom left the yellow triangle with "!" warning "Error on page."
the details give this very unhelpful message:

Line: 2829
Char: 23
Error: Sys.ArgumentException: Value must not be null for Controls and Behaviors. Parameter name: element
Code: 0

where is this Line 2829? I know of no parameter named "element"... how does one track down such an error?

I hate this. and the only thing worse than Microsoft is everything else!

Monday, July 9, 2007

asp.net: how to autoGenerateSelectButton on gridView manually...

(I'll preface my post with "so" as the stereotypical microsoftie does)...

so I have this asp.net application that displays a grid of data. I want the user to be able to click anywhere on any row of that grid to start editing that row; something like data entry on a spreadsheet, but a little more controlled. dotNet 2.0 introduced a new control "gridview" to replace whatever else was used before. the event that gridview has that I want to use to trigger going into edit mode is SelectedIndexChanged - seems like a simple way to ID the row of interest and work on it. "seems" is the key word, because actually they made it hard to fire the event if you want to do anything different from the (ugly) way the control designers premade for you...

what they want you to do is use the "AutoGenerateEditButton" property to do the magic. funny they call it AutoGenerateEdit "Button" because it makes a URL looking link on the grid - not a button! then when you edit in the grid things jump around to fit the new fields that pop into the cells. looks awful.

so what you have to do to fake it out (which I'd rather not have to do, but there you go) was revealed on a google group search here

the trick is in Page_Load to add this code:

for (int i = 0; i++)
{
GridView1.Rows[i].Attributes.Add("onclick",
ClientScript.GetPostBackEventReference(GridView1, "Select$" + i));
}

(sorry I haven't figured how to make code format right under html yet).
also in the .aspx <%@ Page... %>directive you have to add a property not shown in VS: EnableEventValidation="False"

it works, but yuck! next, can I tackle edit mode?...

Sunday, July 8, 2007

new blog!

I decided today to devote a blog to my adventures in coding -- maybe this will garner more interest than my other non-work-related personal musings. so yes, posts here will primarily relate to my real job. stay tuned, ideas are gestating already!

About Me

My photo
smug SoCal catalyst prone to puffery. practitioner of verbal aikido. pearl caster for swine. professional. intuitive. clean. approachable. unique. forgiven sinner. ubiquitous. reads. geekiness rating ~10%. Meyers-Briggs = iNTj. musical thinker. into nature. project manager for a decent place which gives plenty of time, money and chances to prove his talent. dabbler, a dilettante, jack of all trades, master of none. lives in a nice place with a great wife and kids. his boys and attitude keeps him young. hangs out a lot, never bored. listens to XM. doesn't do favorites. tries to play the blues on acoustic guitar. loves the beach. draws. chillz' an groovz'. smokes a pipe. lefty.