RE: What's so special about "Update"

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi David,

I think there is no such method to bind the parameter with the controls one
time. If the command is the UpdateCommand, the DataControl would bind the
parameter automatically and then call the SqlDataSource's Update() method.
But the Custom Command still needs to assign the parameter.

As a workaround, you can set the CustomButton's CommandName as "Update" and
assign a different CommandArgument value. Thus, you can execute some
operations based on the CommandArgument value in the ItemCommand event.

--
Sincerely,

Zhi-Qiang Ni

Microsoft Online Support


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

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
==================================================

--------------------
| Thread-Topic: What's so special about "Update"
| thread-index: Acpt8mkChdHsV7w5QBWKVz0GUzDRdg==
| X-WBNR-Posting-Host: 12.159.35.67
| From: David <DavidLBlackDeck@xxxxxxxxxxxxxxxx>
| References: <37C917B1-ECC6-4263-9FED-4665A06AE90B@xxxxxxxxxxxxx>
<BRzQp2QbKHA.3976@xxxxxxxxxxxxxxxxxxxxxx>
| Subject: RE: What's so special about "Update"
| Date: Wed, 25 Nov 2009 09:12:04 -0800
| Lines: 189
| Message-ID: <872DBFF9-D15C-46F9-B763-5A1844F31F4B@xxxxxxxxxxxxx>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4325
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Path: TK2MSFTNGHUB02.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:94563
| NNTP-Posting-Host: tk2msftsbfm01.phx.gbl 10.40.244.148
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| OK. Thanks. I thought there would be a quick, one line, method of
telling
| the code to transfer all of the bound values to their corresponding
| parameters.
|
| "Zhi-Qiang Ni[MSFT]" wrote:
|
| > Hi David,
| >
| > When an individual item is set to edit mode, the values that can be
changed
| > are usually displayed in text boxes or other controls in which users
can
| > make their changes. I assume that you would like to add a custom
command to
| > a LinkButton which in the FormView's edit mode and then to update the
| > DataSource in the custom command event. Please tell me If I have
| > misunderstood you.
| >
| > The ItemCommand event is not like the Update event (or UpdateCommand
event
| > in DataList control) which can assign the parameter value
automatically.
| > Although the SqlDataSource has its established UpdateCommand statement
and
| > UpdateParameters, we still need to extract the values from the controls
in
| > the current item and pass them to the data source control for an update
| > operation.
| >
| > Here is a sample code:
| > Page side code:
| > <EditItemTemplate>
| > ID:
| > <asp:Label ID="IDLabel1" runat="server" Text='<%#
| > Eval("ID") %>' />
| > <br />
| > Field1:
| > <asp:TextBox ID="Field1TextBox" runat="server"
Text='<%#
| > Bind("Field1") %>' />
| > <br />
| > Field2:
| > <asp:TextBox ID="Field2TextBox" runat="server"
Text='<%#
| > Bind("Field2") %>' />
| > <br />
| > <asp:LinkButton ID="UpdateButton" runat="server"
| > CausesValidation="True" CommandName="Update"
| > Text="Update" />
| > <asp:LinkButton ID="LinkButton1" runat="server"
| > CausesValidation="True" CommandName="SpecialUpdate"
| > Text="SpecialUpdate" />
| > <asp:LinkButton ID="UpdateCancelButton" runat="server"
| > CausesValidation="False"
| > CommandName="Cancel" Text="Cancel" />
| > </EditItemTemplate>
| > Code-Behind:
| > protected void FormView1_ItemCommand(object sender,
| > FormViewCommandEventArgs e)
| > {
| > if (e.CommandName == "SpecialUpdate") //The custom button.
| > {
| > String id =
| > ((Label)FormView1.FindControl("IDLabel1")).Text;
| > String field1 =
| >
((TextBox)FormView1.FindControl("Field1TextBox")).Text;
| > String field2 =
| >
((TextBox)FormView1.FindControl("Field2TextBox")).Text;
| >
| > SqlDataSource1.UpdateParameters["ID"].DefaultValue
| > = id;
| > SqlDataSource1.UpdateParameters["Field1"].DefaultValue
| > = field1;
| > SqlDataSource1.UpdateParameters["Field2"].DefaultValue
| > = field2;
| > SqlDataSource1.Update();
| >
| > FormView1.DataBind();
| > FormView1.ChangeMode(FormViewMode.ReadOnly);
| > }
| > }
| > Some related tutorial:
| > http://msdn.microsoft.com/en-us/library/90xwe9s3.aspx
| > http://www.asp.net/learn/data-access/tutorial-28-cs.aspx
| > http://www.asp.net/learn/data-access/tutorial-46-cs.aspx
| >
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasou
| > rce.update.aspx
| >
| > Have my reply helped?
| >
| > --
| > Sincerely,
| >
| > Zhi-Qiang Ni
| >
| > Microsoft Online Support
| >
| >
| > ==================================================
| > Get notification to my posts through email? Please refer to
| >
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
| >
| > 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
| > ==================================================
| >
| > --------------------
| > | Thread-Topic: What's so special about "Update"
| > | thread-index: Acpp8SkJAixuIYYQQY2bjnF3TBx5sQ==
| > | X-WBNR-Posting-Host: 12.159.35.67
| > | From: David <DavidLBlackDeck@xxxxxxxxxxxxxxxx>
| > | Subject: What's so special about "Update"
| > | Date: Fri, 20 Nov 2009 06:53:03 -0800
| > | Lines: 46
| > | Message-ID: <37C917B1-ECC6-4263-9FED-4665A06AE90B@xxxxxxxxxxxxx>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | charset="Utf-8"
| > | Content-Transfer-Encoding: 7bit
| > | X-Newsreader: Microsoft CDO for Windows 2000
| > | Content-Class: urn:content-classes:message
| > | Importance: normal
| > | Priority: normal
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4325
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | Path: TK2MSFTNGHUB02.phx.gbl
| > | Xref: TK2MSFTNGHUB02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:94432
| > | NNTP-Posting-Host: tk2msftibfm01.phx.gbl 10.40.244.149
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | I have a standard, boilerplate FormView object that I've place on a
page.
| >
| > | The associated sqlDataSource has an update command configured, again,
| > using
| > | the standard, off the shelf, stuff, so it has the standard
linkbuttons
| > for
| > | update, insert, etc. In the formview object in the templates, it has
the
| > | usual set of text boxes that are bound to values in the data row.
| > |
| > | I do have one non-standard button, that is supposed to do something
with
| > | some of the inputs before passing them on to the application. What I
| > want is
| > | to take detect the button press, do some processing, and then pass
the
| > | processed values along, just as if the "update" command has been
issued.
| > The
| > | problem I have is that if I issue the "update" command, by pressing
the
| > | standard "Update" linkbutton, all the values from the form get bound
to
| > the
| > | appropriate data in the database. If I press the other button, none
of
| > the
| > | values are bound. What do I have to do to bind those values?
| > |
| > | The code I have is something like this:
| > |
| > | protected void FormView1_ItemCommand(object sender,
| > | FormViewCommandEventArgs e)
| > | {
| > |
| > | if (e.CommandName == "SpecialUpdate") //The custom button.
| > | {
| > |
| > | //do some stuff
| > |
| > | // FormView1.DataBind(); I tried this but it didn't work.
| > | sqlDataSource1.Update();
| > |
| > | }
| > | }
| > |
| > | protected void sqlDataSource1_Updating(object sender,
| > | SqlDataSourceCommandEventArgs e)
| > | {
| > |
| > | //If I examine the parameters at this point, if I hit the
standard
| > | "Update" linkbutton, all the parameters are bound to their values.
If I
| > got
| > | here pressing the "SpecialUpdate" button, all of the parameters are
null.
| > |
| > | //If I proceed at this point, the data values in the database
will
| > all
| > | be set for "null", instead of taking their values from the input form.
| > | }
| > |
| > |
| > |
| > |
| >
| > .
| >
|

.



Relevant Pages

  • Re: newbie question: Can I modify MFC source code?
    ... When the command finally got to my window (which was the active ... it then looked up the command in its own table of controls and set the value in the ... may ak why I do not use structs for this, well I may do that in light of what I've learned here but my original problem was to store those const variables in const classes so I can also benefit from functionality of classes to do sum calculations on some parameters of these const commands. ... I try very hard not to use global variables these days and I've found it makes debugging and cleaning up much easier. ...
    (microsoft.public.vc.mfc)
  • Re: newbie question: Can I modify MFC source code?
    ... All edit controls were in the same range, ... When the command finally got to my window (which was ... what I've learned here but my original problem was to store those const ... I try very hard not to use global variables these days and I've found ...
    (microsoft.public.vc.mfc)
  • Intercept "Print" Word 2010
    ... "The FilePrint command, built-in or macro, seems to be obsolete. ... it appears that none of the built-in controls of the Backstage UI can ...
    (microsoft.public.word.vba.general)
  • Re: Intercept "Print" Word 2010
    ... This process was pretty straight forward in Word 2003 where I simply used macros named "FilePrint" and "FileDefaultPrint" to intercept the user actions and test for proper margins. ... I repurposed the "FilePrint" and "FileQuickPrint" ribbon controls and used a VBA callback to test for proper margins. ... "The FilePrint command, built-in or macro, seems to be obsolete. ... From what I have been able to determine so far, this "Print" button is a built-in control that is part a "GroupPrintSetting" built-in group, that is part of a "PrintTab" built-in tab, that is part of the new Backstage UI. ...
    (microsoft.public.word.vba.general)
  • Re: More ASP.Net Newbie Questions
    ... The Command is then what you're doing with this connection, ... In regards to your final point, making grids and controls in general do ... > Connection and Recordset objects into, like, 37 different things. ...
    (microsoft.public.dotnet.framework.aspnet)