Click here to Skip to main content
13,290,595 members (57,938 online)
Rate this:
Please Sign up or sign in to vote.
See more:
i have table in sqlserver i want to delete rows through gridview using sqlserver in thnx in advance
Posted 29-Nov-12 20:54pm
__TR__ 30-Nov-12 1:59am
This is not a good question. Use "Improve question" widget to update your question and provide more details on what is it you need help with.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use the following steps.

1) assign ID's (Primary Key) to Gridview
2) Use Gridview Row Deleting event.(using Command name)
3) Get the ID of row clicked by user to Delete.
4) Use ID in delete sql query & execute sql command.
5) Bind Gridview after successful deletion of row.

Use the following code.
protected void gvAcceptanceStatus_RowDeleting(object sender, GridViewDeleteEventArgs e)
        string ObvID =gvAcceptanceStatus.Rows[e.RowIndex].Cells[3].Text.ToString();
               string ObvID=gvAcceptanceStatus.DataKeys[index].Values["ObservationID"].ToString();
            SqlCommand cmd = new SqlCommand("sp_DeleteInfo", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            catch (Exception ex)
                throw new Exception("Exception adding account. " + ex.Message);

In aspx page:-
<asp:gridview id="gvAcceptanceStatus" runat="server" autogeneratecolumns="False" datakeynames="ObservationID" onrowdeleting="gvAcceptanceStatus_RowDeleting">

Convert it to VB.NET.

Hope this helps. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171207.1 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100