kumartyr
kumartyr

Reputation: 305

How to Delete /Edit a row in GridView dynamically with Buttons present in grid itself

How to Delete / Edit a row in GridView dynamically with Buttons present in GridView itself

I have tried RowDeleting event for deleting & RowEditing for Edit.But, I can't get the desired result

Using VS2005 asp.net C# 2.0

below is what I tried in RowDeleting event

protected void GridViewFRM_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        if (connection.State == ConnectionState.Closed)
        {
            connection.Open();
        }
        OracleCommand OLCOM3 = new OracleCommand();
        OLCOM3.CommandText = "Delete from FORUM WHERE QUESTION='" + GridViewFRM.DataKeys[e.RowIndex].Values[0].ToString() + "'";
        OLCOM3.ExecuteNonQuery();
        DisplayUserData();
    }

Upvotes: 0

Views: 1573

Answers (2)

Vinay Rajput
Vinay Rajput

Reputation: 372

You can follow this http://www.codeproject.com/Tips/564619/Example-of-gridview-rowcommand-on-Button-Click

Change the command name according to your convince. but do not use "delete/edit" because we are using row command not edit /delete command.

Upvotes: 0

Saad Surya
Saad Surya

Reputation: 505

Give command name to edit and delete button

<asp:ImageButton runat="server" id="editBtn" commandName="Edit"></asp:ImageButton>

Same for Delete

Upvotes: 2

Related Questions