SQLDataSource - UpdateParameters - ControlID RRS feed

  • Question

  • User-498848506 posted

    I am using the following code to UPDATE entries in a "GridView".

    The problem is that I have hardcoded the "ControlID" (ControlID="Gridview1:_ctl2:ItemStatus"), but in reality each line item in the Gridview has a different ControlID. So IF I try to update any record other than the one assigned that ControlID, the update does not work.

    Is there a programmatic way to process either ALL of the UPDATED fields (which come from a parameterized query) at once... or SELECTIVELY ONE at a time where the ControlID could be programatically set.

    Thanks for your assistance!

    UpdateCommand="UPDATE [ClinicTest2].[dbo].[ICDbS_SupplyOrders] SET
    [PickStatus] = @ItemStatusIn
    Where [BasketID]= @BasketNumber AND [ItemNumber] = @ItemNo AND [OrderID] = @OrderID_H ">


    <asp:ControlParameter Name="ItemStatusIn" ControlID="Gridview1:_ctl2:ItemStatus" PropertyName="SelectedItem.Text" Type="String" />

    <asp:ControlParameter Name="BasketNumber" ControlID="Gridview1:_ctl2:BasketID_H" Type="String" />

    <asp:ControlParameter Name="ItemNo" ControlID="Gridview1:_ctl2:ItemNumber_H" Type="String" />

    <asp:ControlParameter Name="OrderID_H" ControlID="Gridview1:_ctl2:OrderID_H" Type="String" />


    Tuesday, June 25, 2013 3:47 PM

All replies

  • User-851967432 posted

    Hey Joe, where ya goin with that gun in  your hand? ha

    You're making it more difficult than it needs to be. First of all, nothing good can come from hard coding.

    The easiest way to approach this is through binding wizard. 

    1. Drag n Drop your gridview on the form
    2. Click in the upper right hand corner to pop up the binding option
    3. Walk through the wizard
    4. As your going through the wizard, you'll notice you can apply inserts, updates, and deletes via tabs either by hardcoding a query or a prewritten script. By doing this, the wizard will create the asp.net script for you.
    Tuesday, June 25, 2013 4:22 PM
  • User-1716253493 posted

    Why not using BIND("FieldName") for the control property?

                <asp:Parameter Name="ItemStatusIn" Type="String" />
                <asp:Parameter Name="BasketNumber" Type="String" />
                <asp:Parameter Name="ItemNo" Type="DateTime" />
                <asp:Parameter Name="OrderID" Type="String" />

    Tuesday, June 25, 2013 11:40 PM
  • User-498848506 posted

    Hi, Thanks for responding...

    I tried:

    <asp:ControlParameter Name="ItemStatusIn" ControlID='<%# Container.DataItem("ItemStatus") %>' PropertyName="SelectedItem.Text" Type="String" />
    Parser Error Message: Databinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.ControlParameter does not have a DataBinding event.

    And as you suggested:
    BIND("ItemStatus") It did not work either... Perhaps I have the wrong syntax? would you know??



    Neither worked...

    Wednesday, June 26, 2013 7:35 AM