What's so special about "Update"

Discussion in 'ASP .Net' started by David, Nov 20, 2009.

  1. David

    David Guest

    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.
    }
     
    David, Nov 20, 2009
    #1
    1. Advertisements

  2. 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 <>
    | Subject: What's so special about "Update"
    | Date: Fri, 20 Nov 2009 06:53:03 -0800
    | Lines: 46
    | Message-ID: <>
    | 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.
    | }
    |
    |
    |
    |
     
    Zhi-Qiang Ni[MSFT], Nov 24, 2009
    #2
    1. Advertisements

  3. David

    David Guest

    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.

     
    David, Nov 25, 2009
    #3
  4. 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 <>
    | References: <>
    <>
    | Subject: RE: What's so special about "Update"
    | Date: Wed, 25 Nov 2009 09:12:04 -0800
    | Lines: 189
    | Message-ID: <>
    | 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 <>
    | > | Subject: What's so special about "Update"
    | > | Date: Fri, 20 Nov 2009 06:53:03 -0800
    | > | Lines: 46
    | > | Message-ID: <>
    | > | 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.
    | > | }
    | > |
    | > |
    | > |
    | > |
    | >
    | > .
    | >
    |
     
    Zhi-Qiang Ni[MSFT], Nov 27, 2009
    #4
  5. Hi David,

    This is Zhi-Qiang Ni from MSDN Managed Newsgroup support team, since I
    haven't seen your reply after I last posted my reply, I'm writing to check
    the status of this post. Please feel free to let me know if there's
    anything else I can help.

    Thanks.

    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 <>
    | References: <>
    <>
    | Subject: RE: What's so special about "Update"
    | Date: Wed, 25 Nov 2009 09:12:04 -0800
    | Lines: 189
    | Message-ID: <>
    | 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 <>
    | > | Subject: What's so special about "Update"
    | > | Date: Fri, 20 Nov 2009 06:53:03 -0800
    | > | Lines: 46
    | > | Message-ID: <>
    | > | 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.
    | > | }
    | > |
    | > |
    | > |
    | > |
    | >
    | > .
    | >
    |
     
    Zhi-Qiang Ni[MSFT], Dec 1, 2009
    #5
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.