Formview, missing data on newvalues, oldvalues, keys

D

David

Hello.

I have a formview object that shows a record and lets users update
fields, and they then press the "update" button, and I want it to update. It
looks like pretty standard stuff, but it doesn't update.

Here's my formview declaration, followed by the usual string of text boxes,
labels, etc. all bound to fields. They work.

<asp:FormView ID="FormView1" runat="server" DataKeyNames="RFQID"
DataSourceID="SqlDataSourceRFQ"
onitemcommand="FormView1_ItemCommand"
onitemupdating="FormView1_ItemUpdating"
onmodechanged="FormView1_ModeChanged" Width="100%">

None of the methods do anything special. They just set a couple of
variables. That will be used in later processing, except it never gets to the
later processing. It ends up throwing an exception during the Update.

The fields are all displayed correctly, with the correct data.

The Update button is just the default linkbutton

<asp:LinkButton ID="UpdateButton" runat="server"
CausesValidation="True"
CommandName="Update" Text="Update" />

I notice when I set a breakpoint in the onitemupdate function, I can examing
newvalues, oldvalues, and keys. None of them have any data. They are all
zero length collections.

What happened to the data? What would prevent the data from being sent to
the onitemupdate event handler?
 
A

Allen Chen [MSFT]

Hi David,
None of the methods do anything special. They just set a couple of
variables. That will be used in later processing, except it never gets to the
later processing. It ends up throwing an exception during the Update.

Could you tell me the exception message first?

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David

Yes. I get a Null value message on the update. All of the parameters in the
Update statement end up being set to null, so when the sqldatasource object
goes to execute the update, it fails on a field that does not allow nulls.

(Hmmm....Maybe I'll put in a required field validator on one of them, and
make sure it is passing. I suspect it will, but I haven't tried it yet.)
 
A

Allen Chen [MSFT]

Hi David,
Yes. I get a Null value message on the update. All of the parameters in the
Update statement end up being set to null, so when the sqldatasource object
goes to execute the update, it fails on a field that does not allow nulls.
(Hmmm....Maybe I'll put in a required field validator on one of them, and
make sure it is passing. I suspect it will, but I haven't tried it yet.)


Thanks for your reply. From your description the parameters are somehow
lost before updating, right? Could you send me a demo that can reproduce
this issue? My email is (e-mail address removed) update here after
sending the project in case I missed that email.

Regards,
Allen Chen
Microsoft Online Support
 
D

David

I tried to strip out as much as I could, and in the course of the action, I
found the offending statements. It seems that the problem is somehow related
to enclosing the fields of the edit template inside a table. I, of course,
had no clue about this, and still don't know what the deal is.

At any rate, this one doesn't work:


<EditItemTemplate>
<asp:Table ID="tblRFQ" runat="server" Width="100%">
<asp:TableRow>
<asp:TableCell ID="tbcRFQ" runat="server" Width="30%">RFQID:
<asp:Label ID="RFQIDLabel1" runat="server" Text='<%#
Bind("RFQID") %>' />

</asp:TableCell><asp:TableCell ID="tbcTitle" runat="server"
Width="40%"><asp:Label ID="lblFormTitle" runat="server" Text="Sales
Initiation Form" Font-Size="Large"
Width="30%"></asp:Label></asp:TableCell><asp:TableCell ID="tbcQuoteDate"
runat="server" Width="30%"></asp:TableCell></asp:TableRow><asp:TableRow
Width="100%">
said:
</asp:TextBox>
<asp:RequiredFieldValidator ID="requestorrequired" runat="server"
ControlToValidate="tbRequestor" Text="Required"></asp:RequiredFieldValidator>
</asp:TableCell></asp:TableRow></asp:Table><br />

<asp:LinkButton ID="UpdateButton" runat="server"
CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel"/>
</EditItemTemplate>



This one works fine:

<EditItemTemplate>


RFQID:
<asp:Label ID="RFQIDLabel1" runat="server" Text='<%#
Bind("RFQID") %>' />

<asp:Label ID="lblFormTitle" runat="server" Text="Sales Initiation
Form" Font-Size="Large" Width="30%"></asp:Label>
Requestor: <asp:TextBox ID="tbRequestor" runat="server" Text='<%#
Bind("Requestor") %>' ></asp:TextBox>
<asp:RequiredFieldValidator ID="requestorrequired" runat="server"
ControlToValidate="tbRequestor" Text="Required"></asp:RequiredFieldValidator>
<br />

<asp:LinkButton ID="UpdateButton" runat="server"
CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel"/>
</EditItemTemplate>


The only difference is that the table, and its tablerow and tablecell
objects, have been removed from the markup. The first indication I get of a
problem is in the ItemUpdating event handler. When the fields are enclosed
in a table, the "OldValues" field has a 0 length array. When there is no
table, it is an array of length 1 (the requestor.) The required field
validator works fine for both cases.


So, as I'm sure happens often, the thing that was causing the problem is
something I omitted from my original description. My modified question is
what do so that the values bound to data inside the table is updated and
passed on to the Update event of the ItemUpdating field of my formview, and
then to my Updating even of the SQLDataSource.
 
Joined
Nov 3, 2009
Messages
1
Reaction score
0
Formview Updatecommand is passing Nulls to SQL Query

I have created an EditItemTemplate in my Formview. The ItemTemplate displays the information correctly, Pressing Edit brings up the EditItemTemplate nicely. When I edit some fields and press Update it sends a query off to the SQL server but it my SQL trace reveals that sends it with a NULL in every the parameters. Since I have correctly identified the DataKeyNames value it finds the right record and overrights all the values with nulls. And also i dont have any ASP:Table object in my EditItemTemplate. I am stuck here big time. Need your urgent help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top