1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

how to delete data form the grid view

Discussion in 'C#' started by seo-india, Aug 16, 2010.

  1. #1
    Dear user tell me about this how to do
    SEMrush
     
    seo-india, Aug 16, 2010 IP
    SEMrush
  2. bulochc83

    bulochc83 Peon

    Messages:
    260
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    when you create a grid view then you will already create delete button then you can delete that data or insert data.by query fire.
     
    bulochc83, Sep 24, 2010 IP
  3. Employwise

    Employwise Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    To delete a row from gridview ,first enable delete button true. write sql query delete from tablename where columnvalue=@columnname in sqldatasource.
     
    Employwise, Sep 28, 2010 IP
  4. Deu

    Deu Peon

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #4
    add delete button to the gv
     
    Deu, Oct 10, 2010 IP
  5. deepender

    deepender Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    if you want to delete data from grid view than you just need to plug a delete link and need to insert a delete query than it can easily deleted from you table.
     
    deepender, Oct 18, 2010 IP
  6. annie25

    annie25 Guest

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i have done my six month training in asp.net...now i am working on a live project and i am unable to delete data from grid view...please can any suggest me.
     
    annie25, Oct 23, 2010 IP
  7. akshaykalia

    akshaykalia Member

    Messages:
    77
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #7
    This does the trick for me :
    in the gridview tag , under columns , add :


    <asp:gridview onRowDataBound="addConfirm" DataSourceID="messages">
    <columns>

    // Other columns with stuff

    <asp:templatefield AccessibleHeaderText="Delete">
    <itemtemplate>
    <asp:linkbutton runat="server"
    id="rowToDelete" commandname="Delete" Text="Delete" />

    </itemtemplate>
    </asp:templatefield>
    </columns>
    </asp:gridview>


    and add SQLdatasource

    <asp:SqlDataSource id="messages" runat="server" ConnectionString="<%$ ConnectionStrings:AkshayConnectionString %>" SelectCommand="blah blah blah" DeleteCommand="DELETE FROM table_name WHERE id=@id">
    <DeleteParameters>
    <asp:parameter Name="id" />
    </DeleteParameters>


    and in the .cs file , i use this function :


    protected void addConfirm(Object src, GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    DataRowView rowView = (DataRowView)e.Row.DataItem;
    string name = rowView["title"].ToString().Trim();
    LinkButton linkButton = (LinkButton)e.Row.FindControl("rowToDelete");
    linkButton.Attributes["onClick"] = "javascript:return confirm ( 'Do you wish to delete " + name + " ?' )";
    }
    }
     
    akshaykalia, Nov 1, 2010 IP
  8. shiv.cec

    shiv.cec Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    protected void grdview1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
    int catid = Convert.ToInt32(grdview1.DataKeys[e.RowIndex].Value);

    conn.Open();
    SqlCommand cmd = new SqlCommand("delete emp where rowid=" + catid+ "", conn);
    cmd.ExecuteNonQuery();
    conn.Close();
    bind();


    }
     
    shiv.cec, Nov 1, 2010 IP
  9. teamaguilar

    teamaguilar Peon

    Messages:
    197
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    teamaguilar, Nov 21, 2010 IP