how to update multiple rows (linq,sql) gridview RRS feed

  • Question

  • <div class="row">
                <div class="col-md-9">
                    <asp:Label ID="Label1" runat="server" Text="Order Number"></asp:Label>&nbsp;&nbsp;
                    <asp:DropDownList ID="OrderDLL" runat="server"
                    Width="100px" DataSourceID="OrderDLLODS" 
                    <asp:Button ID="OrderFetch" runat="server" Text="Fetch" OnClick="OrderFetch_Click" />&nbsp;&nbsp;
                    <asp:ListView ID="CustomerInfo" runat="server" DataSourceID="CustomerDLLODS">
                            <asp:Label ID="Customer" runat="server" Text="Customer: "></asp:Label>&nbsp;&nbsp;
                            <asp:Label ID="TracksBy" runat="server" Text='<%# Eval("LastName")+", "+Eval("FirstName") %>'></asp:Label>&nbsp;&nbsp;
                            <asp:Label ID="Contact" runat="server" Text="Contact: "></asp:Label>&nbsp;&nbsp;
                            <asp:Label ID="SearchArg" runat="server" Text='<%# Eval("Phone") %>'></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:Label ID="Label3" runat="server" Text="Picker"></asp:Label>&nbsp;&nbsp;
                    <asp:DropDownList ID="PickerDLL" runat="server"
                    Width="150px" DataSourceID="PickerDLLODS" 
        <asp:GridView ID="OrderList" runat="server" AutoGenerateColumns="False" GridLines="Horizontal" CssClass="table">
                            <asp:TemplateField HeaderText="Product">
                                    <asp:Label runat="server" ID="Product"  Width="180px" Text='<%# Eval("Product") %>'></asp:Label>
                            <asp:TemplateField HeaderText="Qty">
                                    <asp:Label runat="server" ID="QtyOrdered" Width="40px"
                                        Text='<%# Eval("QtyOrdered") %>'></asp:Label>
                            <asp:TemplateField HeaderText="Comment">
                                    <asp:Label ID="CustomerComment" runat="server" Text='<%# Eval("CustomerComment") %>'></asp:Label>
                            <asp:TemplateField HeaderText="Picked">
                                    <asp:TextBox runat="server" ID="QtyPicked" Width="60px" Text='<%# Bind("QtyPicked") %>'></asp:TextBox>
                            <asp:TemplateField HeaderText="Pick Issue">
                                    <asp:TextBox ID="PickIssue" runat="server" Width="100px" Text='<%# Bind("PickIssue") %>'></asp:TextBox>
                            No data to view for the Active Order.
        <asp:Button ID="Save" runat="server" Text="Save" Width="200px" OnClick="Save_Click"/>
        <asp:ObjectDataSource ID="OrderDLLODS" runat="server" 
        <asp:ObjectDataSource ID="CustomerDLLODS" runat="server" 
                <asp:ControlParameter ControlID="OrderDLL" PropertyName="SelectedValue" Name="CustomerID" Type="int32"></asp:ControlParameter>
        <asp:ObjectDataSource ID="PickerDLLODS" runat="server" 

    • Moved by CoolDadTx Monday, December 2, 2019 3:07 PM ASP.NET related
    Friday, November 29, 2019 10:28 PM

All replies

  • Hello,

    While your code is C# a better place to ask your question is in the ASP.NET developer forums.

    Also, you need to indicate version of ASP.NET e.g. ASP.NET or ASP.NET Core, how data is accessed e.g. DataSet, DataTable, Entity Framework, Entity Framework Core.

    There are going to be many different paths to take and don't get hung up on LINQ as LINQ is not for updating, deleting and adding when working with Entity Framework per-say but a conduit to feed changes to EF. 

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Saturday, November 30, 2019 12:31 AM
  • Hi johnnybuns,
    According to your requirements, if you need to update multiple data to GridView at the same time, you need to add checkboxes to operate.
    By clicking on the checkbox of the line you need to update, trigger the click event of chekcbox. In this event, the modifiable columns of the corresponding rows will be displayed in the modifiable form. 
    After all modifications, click the update button to trigger the code behind click event. In this event, update all the changed values by cycling the current GridView rows, and then rebind the data source.
    For the current requirements, I suggest that you can use the code behind to bind data sources instead of ObjectDataSource, which will be more convenient for your update query operation.
    Here is a simple case and you can refer to it.
    [Bulk Edit Update Multiple Rows in ASP.Net GridView using CheckBoxes]
    Best Regards,
    Daniel Zhang

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, December 2, 2019 9:48 AM
  • Please post questions related to ASP.NET in the ASP.NET forums.

    Michael Taylor

    Monday, December 2, 2019 3:06 PM