Delete Row From Gridview On Click Of Delete Link In A Column

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sudhashekhar30
    New Member
    • Sep 2007
    • 44

    Delete Row From Gridview On Click Of Delete Link In A Column

    HI all
    I am using gridview. i have added a column "delete" in gridview through wizard. i want to delete record on the click of respective delete link.
    ------------inline code---------
    [code=asp]
    <asp:GridView ID="GridView1" runat="server" OnSelectedIndex Changed="GridVi ew1_SelectedInd exChanged">
    <Columns>
    <asp:CommandFie ld ShowDeleteButto n="True" />
    </Columns>
    </asp:GridView>[/code]
    -----------------------------------------------
    i need coding for code behind .
    thanks
    regards
    sudha
    Last edited by Frinavale; Oct 31 '07, 06:35 PM. Reason: Added [code] tags to make more legible
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    Have you searched Google yet? I know there are many useful examples that include the html and the code behind.

    Nathan

    Comment

    • Saad Alam
      New Member
      • Oct 2007
      • 27

      #3
      I recommend you to set DataKeyNames property (Example: Give primary key column name) in that way you will retrieve primary key to perform deletion, after that you will need to add a RowDeleting event. In that event handler you have to add a code similar to this:
      [code=cpp]
      protected void GridView1_RowDe leting(object sender, GridViewDeleteE ventArgs e)
      {
      //First Retrieve Primary Key
      Int id = GridView1.DataK eyNames(e.RowIn dex);
      //Here You will perform deletion simply hit a delete query to the database using the //id that you have retrieved
      DeleteRow();
      //Rebind data to updated data
      GridView1.DataS ource=GetUpdate dData();
      GridView1.DataB ind();
      }[/code]
      Last edited by Frinavale; Oct 31 '07, 06:36 PM. Reason: Added [code] tags to make more legible

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Please review the Tutorial on how to use the GridView control found on MSDN here.

        Thanks

        -Frinny

        Comment

        Working...