When i try to update the row in datagridview, it doesn't get updated into database. Nothing happens when i change the fields. Not even the delete command is working.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="existBill2.aspx.cs" Inherits="existBill2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Editing Existing Bill</title>
    <form id="form1" runat="server">
        <asp:Image ID="Image1" runat="server" Height="102px" 
        ImageUrl="~/images/21stcy.jpg" Width="1003px" />    
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
            DataSourceID="SqlDataSource2" DataTextField="billNo" DataValueField="billNo">
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:21centuryConnectionString1 %>" 
            ProviderName="<%$ ConnectionStrings:21centuryConnectionString1.ProviderName %>" 
            SelectCommand="select billNo from tbl_bill"></asp:SqlDataSource>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataSourceID="SqlDataSource1" AutoGenerateEditButton="true" AutoGenerateDeleteButton="true" DataKeyNames="item_id">
                <asp:BoundField DataField="item_id" HeaderText="item_id" 
                    SortExpression="item_id" />
                <asp:BoundField DataField="art_no" HeaderText="art_no" 
                    SortExpression="art_no" />
                <asp:BoundField DataField="item_color" HeaderText="item_color" 
                    SortExpression="item_color" />
                <asp:BoundField DataField="item_size" HeaderText="item_size" 
                    SortExpression="item_size" />
                <asp:BoundField DataField="item_category" HeaderText="item_category" 
                    SortExpression="item_category" />
                <asp:BoundField DataField="item_price" HeaderText="item_price" 
                    SortExpression="item_price" />
                <asp:BoundField DataField="item_quantity" HeaderText="item_quantity" 
                    SortExpression="item_quantity" />

        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:21centuryConnectionString1 %>" 
            ProviderName="<%$ ConnectionStrings:21centuryConnectionString1.ProviderName %>" 
            SelectCommand="SELECT item_id, art_no, item_color, item_size, item_category, item_price, item_quantity from tbl_items where billNo=?bill_no"
             UpdateCommand="Update tbl_items set art_no=@artNo, item_color=@iColor, item_size=@iSize, item_category=@iCategory, item_price=@iPrice, item_quantity=@iQuantity where item_id=@itemID"
             DeleteCommand="DELETE FROM tbl_items WHERE item_id=@itemID" >
                <asp:ControlParameter ControlID="DropDownList1" PropertyName="SelectedValue" Name="bill_no" Type="Int32" />
                <asp:Parameter Name="artNo" Type="String" />
                <asp:Parameter Name="iColor" Type="String" />
                <asp:Parameter Name="iCategory" Type="String" />
                <asp:Parameter Name="iPrice" Type="Int32" />
                <asp:Parameter Name="iSize" Type="Int32" />
                <asp:Parameter Name="iQuantity" Type="Int32" />
                <asp:Parameter Name="itemID" Type="Int32" />
                <asp:Parameter Name="itemID" Type="Int32" />


Can you run SQL Profiler (or similar tool) to see if there are errors on the SQL server or if your statements are even running?

Please help me solve my problem. It's really important.

Dear my experience in asp.net and Microsoft Sql Server , in the asp.net application say you are using ADO.net you need to call sqlDataAdapter.Update(param) , say you are using LINQ technology you to retrieve the row and update it then call the submitChanges method , simply to submit the changes back to the data base , may be and may be not this is the missing part of your code
best regards
Omar Adnan

Could you please elaborate more on what you've said?

i thing when you binding Grdiview then you didn't use IsPostback propery in page load.

try ...
it will solve your problem


It's been a little while since I have used GridViews, so you'll have to bear with me. You may try adding the "OnEvent" values to the GridView tag. Such as "OnRowDeleting" or "OnRowDeleted" you can either add code behind or add script to your page to alert the page as to how to react to an event. I have not often used the SQL Data Source object, as I normally use LINQ, but hopefully this article may be of some use.

Hope that helps.

Thanks.. finally somebody replied on this post.. I haven't checked the code properly but i think this might be useful :)