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">
                <LayoutTemplate>
                    <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
                </LayoutTemplate>
                <ItemTemplate>
                    <div>
                    <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?')" />
                    </div>
                </ItemTemplate>
                <EditItemTemplate>
                    <div>
                    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" />
                    </div>
                </EditItemTemplate>
            </asp:ListView>
           
            <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" />
        </form>

    You can also download attached source code.

    image
    ListView.jpg
    318 x 517 - 51K
    ListViewEditDelete.zip
    1M

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

Tagged

Popular Posts of the Week

Optimum Creative