So I’m happily coding away converting a legacy system ( not really legacy I guess, ASP.Net 1.1) and get to a part where I can add some new functionality to the site. I decide to update to the GridView and check things out. CommandField columns are a god send, or so I thought.
So like most real apps out there we all have some sort of DataBind() function in our libraries to preform calls to BLL or DAL’s depending on how things go. So I wire all this up, add some CommandField columns for editing, updating and deleting and start to run through the new part.
First error I get is when I try to cancel the in line edit function. I get an exception thrown stating that I hadn’t wired up the RowCancelingEdit Event. Fine, I don’t see the point but okay I’ll do it. Really at most I set the editindex to -1 and rebind the data. I don’t get why the framework can’t just do that for me only with ViewState data. Anyway, I wire that up. Now comes the huge pain in the ass. I have my RowUpdating event wired up and I notice that the GridViewDeleteEventArgs have concurrency built in with the OldValues and NewValues collection. Sweet! I can get the new value set my BLL value to the new value and hit save and be done. 10 lines of code cut down to 4, fantastic!
If only it was that easy. Instead I get nothing from these collections. Nothing at all. I’ve tried every combo of attributes on the GridView and CommandField column with none of them working. So I did some digging, I couldn’t find any real good examples of people actually databinding the GridView without using the declartive DataSources. I did happen to stumble across a post on the beta forums about this and the result was that I had to find the TextBox control that was generated an get the value that way. If this is so, I don’t see the value in using the GridView at all and will happily switch back to the old busted way. I’d really prefer the new hotness way though.
So if anyone can shed some light on this and hopefully prove me to be just lazy and not very good at google then that would be great.