edit update delete in listview in asp.net c#
  • Hi today i am sharing how can we edit update delete in listview in asp.net using c# with sql server.

     <form id="form1" runat="server">
            <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="id">
                    <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
                    <strong>Name: </strong><%# Eval("name") %>
                    <br />
                    <strong>Price: </strong><%# Eval("Price") %>
                    <br />
                    <strong>Stock: </strong><%# Eval("Stock") %>
                    <br />
                    <asp:LinkButton ID="lnkEdit" runat="server" Text="Edit" CommandName="Edit" /> |
                    <asp:LinkButton ID="lnkDel" runat="server" Text="Delete"
                        CommandName="Delete" OnClientClick="return confirm('Delete this entry?')" />
                    Name: <asp:TextBox ID="txtName" runat="server" Text='<%# Bind("name") %>' />
                    <br />
                    Price: <asp:TextBox ID="txtPrice" runat="server" Text='<%# Bind("Price") %>' />
                    <br />
                    Stock: <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Stock") %>' />
                    <br />
                    <asp:LinkButton ID="lnkSave" Text="Save" runat="server" CommandName="Update" /> |
                    <asp:LinkButton ID="lnkCancel" Text="Cancel" runat="server" CommandName="Cancel" />
            <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                SelectCommand="SELECT * FROM tblProduct"
                UpdateCommand="Update tblProduct SET name=@name, Price=@Price, Stock=@Stock WHERE id=@id"
                DeleteCommand="Delete tblProduct WHERE id=@id" />

    You can also download attached source code.

    318 x 517 - 51K

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook


Popular Posts of the Week

    Optimum Creative