By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,214 Members | 2,072 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,214 IT Pros & Developers. It's quick & easy.

Update command not working with hidden field as a parameter

P: n/a
I have a formview with a datasource that contains a select and update
command. The select statement works fine but the update command doesn't seem
to be working. After some troubleshooting I have narrowed the problem down
to the department_id parameter which is set from a hidden field.

I can confirm this by hard coding the UpdateCommand to: UPDATE configuration
SET special_notes=@special_notes WHERE (student_id=@student_id) AND
(department_id='1234'). I know my hidden field is getting set correctly
because I am do a "view source" on the rendered page and see the department
id being set with no extra spaces, correct case and so forth. Could someone
help me figure out what I am missing? :)

Thanks,
Brad
<asp:SqlDataSource ID="formview_datasource" runat="server"
ConnectionString="Connection Info" ProviderName="System.Data.SqlClient"
SelectCommand="select command" UpdateCommand="UPDATE configuration SET
special_notes=@special_notes WHERE (student_id=@student_id) AND
(department_id=@department_id)" OnSelecting="SetParameters">
<SelectParameters>
<asp:QueryStringParameter Name="student_id"
QueryStringField="student_id" Type="String" />
<asp:Parameter Name="department_id" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:FormParameter FormField="student_id" Name="student_id" />
<asp:FormParameter FormField="department_id" Name="department_id" />
<asp:FormParameter FormField="special_notes" Name="special_notes" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:FormView ID="formview" runat="server"
DataSourceID="formview_datasource" Width="100%">
<EditItemTemplate>
<table>
<tr>
<td class="right_labels">Special Notes:</td>
<td colspan="3" <asp:TextBox ID="special_notes" runat="server"
rows="5" style="width: 85%" Text='<%# Bind("special_notes") %>'
TextMode="MultiLine"></asp:TextBox></td>
</tr>
<tr>
<td align="center" colspan="4">
<asp:HiddenField ID="department_id" Value='<%#
Department.GetDepartmentID() %>' runat="server" />
<asp:HiddenField ID="student_id" Value='<%#
Bind("student_id") %>' runat="server" />
<asp:Button ID="UpdateButton" runat="server"
CausesValidation="True" CommandName="Update" Text="Update"</asp:Button>
</td>
</tr>
</table>
</EditItemTemplate>
</asp:FormView>
Jun 4 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hello Brad,

From your description, you're encountering some problem when using FormView
with some update parameter reference to HiddenField control ,correct?

As for the updating command, what's the exact problem behavior, is there
any error message such as "parameter is not supplied or method signature
not match"?

Based on the aspx template you provided, you've the following
EditTemplate(used for updating command)

===============
<EditItemTemplate>
<table>
<tr>
<td class="right_labels">Special Notes:</td>
<td colspan="3" <asp:TextBox ID="special_notes" runat="server"
rows="5" style="width: 85%" Text='<%# Bind("special_notes") %>'
TextMode="MultiLine"></asp:TextBox></td>
</tr>
<tr>
<td align="center" colspan="4">
<asp:HiddenField ID="department_id" Value='<%#
Department.GetDepartmentID() %>' runat="server" />
<asp:HiddenField ID="student_id" Value='<%#
Bind("student_id") %>' runat="server" />
<asp:Button ID="UpdateButton" runat="server"
CausesValidation="True" CommandName="Update" Text="Update"</asp:Button>
</td>
</tr>
</table>
</EditItemTemplate>
===================

Only "special_notes" and "student_id" is supplied through "Bind" keyword in
binding expression. however, the update parameters in DataSource control
expected three parameters:

================
<UpdateParameters>
<asp:FormParameter FormField="student_id" Name="student_id" />
<asp:FormParameter FormField="department_id" Name="department_id" />
<asp:FormParameter FormField="special_notes" Name="special_notes" />
</UpdateParameters>
</asp:SqlDataSource>
====================

and the <asp:HiddenField ID="department_id" Value='<%#
Department.GetDepartmentID() %>' runat="server" /doesn't seem to be a
valid two-way databinding expression.

Also, I have tried a very simple test with FormView edittemplate using a
HiddenField to reference a primary key column (in database table) and the
updating can work correctly.

You can check the above setting or try a simplified table to see whether
the parameters and binding expression setting is the cause.

If there is any other finding, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 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 or complex
project analysis and dump analysis issues. 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/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 5 '07 #2

P: n/a
><asp:HiddenField ID="department_id" Value='<%#
>Department.GetDepartmentID() %>' runat="server" /doesn't seem to be a
valid two-way databinding expression.
I wasn't trying to update the department_id value, only use it as a SQL
WHERE criteria. Apparently even though I don't want to update it, a two way
databinding expression was what I needed. When I changed the above to read:

<asp:HiddenField ID="department_id" Value='<%# Bind("department_id") %>'
runat="server" />

Everything started to work as I expected.

Thank you! :-)
Brad
"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:R6**************@TK2MSFTNGHUB02.phx.gbl...
Hello Brad,

From your description, you're encountering some problem when using
FormView
with some update parameter reference to HiddenField control ,correct?

As for the updating command, what's the exact problem behavior, is there
any error message such as "parameter is not supplied or method signature
not match"?

Based on the aspx template you provided, you've the following
EditTemplate(used for updating command)

===============
<EditItemTemplate>
<table>
<tr>
<td class="right_labels">Special Notes:</td>
<td colspan="3" <asp:TextBox ID="special_notes" runat="server"
rows="5" style="width: 85%" Text='<%# Bind("special_notes") %>'
TextMode="MultiLine"></asp:TextBox></td>
</tr>
<tr>
<td align="center" colspan="4">
<asp:HiddenField ID="department_id" Value='<%#
Department.GetDepartmentID() %>' runat="server" />
<asp:HiddenField ID="student_id" Value='<%#
Bind("student_id") %>' runat="server" />
<asp:Button ID="UpdateButton" runat="server"
CausesValidation="True" CommandName="Update" Text="Update"</asp:Button>
</td>
</tr>
</table>
</EditItemTemplate>
===================

Only "special_notes" and "student_id" is supplied through "Bind" keyword
in
binding expression. however, the update parameters in DataSource control
expected three parameters:

================
<UpdateParameters>
<asp:FormParameter FormField="student_id" Name="student_id" />
<asp:FormParameter FormField="department_id" Name="department_id" />
<asp:FormParameter FormField="special_notes" Name="special_notes" />
</UpdateParameters>
</asp:SqlDataSource>
====================

and the <asp:HiddenField ID="department_id" Value='<%#
Department.GetDepartmentID() %>' runat="server" /doesn't seem to be a
valid two-way databinding expression.

Also, I have tried a very simple test with FormView edittemplate using a
HiddenField to reference a primary key column (in database table) and the
updating can work correctly.

You can check the above setting or try a simplified table to see whether
the parameters and binding expression setting is the cause.

If there is any other finding, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 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 or complex
project analysis and dump analysis issues. 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/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Jun 5 '07 #3

P: n/a
You're welcome :)

Have a nice day!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 6 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.