Click here to Skip to main content
15,850,103 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to compare grid view row values with the database values like for ex. for a particular id i have four records in table like..
id name
1 A
1 B
1 C
1 D
i m fetching these records in grid view and displaying.If the user deletes any gridview row and tries to update it, i want to compare grid row values with database values and find out which value user has deleted and save that value in any variable before updating in database for further operations.
How can i do this?Help Me
Updated 19-Mar-14 20:35pm
ZurdoDev 20-Mar-14 14:32pm    
Where are you stuck? You know how to read the row and you know how to get data from SQL, right? So, compare them.
pwavell 21-Mar-14 3:35am    
the problem is while fetching i get for ex. four records and if user deletes a grid row from front end and then updates it.i just have to find out which row user has deleted and store that deleted row values for further use.

1 solution

       <asp:gridview runat="server" id="grdDetails" autogeneratecolumns="true" datakeynames="ID,name" onrowdeleting="grdDetails_RowDeleting" xmlns:asp="#unknown">
                       <asp:linkbutton id="lnkdel" runat="server" text="Delete" commandname="Delete"></asp:linkbutton>


protected void Page_Load(object sender, EventArgs e)
            catch (Exception ex)

        private void FillControls()
                DataTable dt = new DataTable();
                dt.Columns.Add("ID", typeof(int));
                dt.Columns.Add("name", typeof(string));
                dt.Rows.Add(1, "A");
                dt.Rows.Add(1, "B");
                dt.Rows.Add(1, "C");
                dt.Rows.Add(1, "D");
                grdDetails.DataSource = dt;

            catch (Exception ex)

        protected void grdDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
            int id = int.Parse(grdDetails.DataKeys[e.RowIndex].Values[0].ToString());
            string name = grdDetails.DataKeys[e.RowIndex].Values[1].ToString();

you can keep both id and name in list for further use.
Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900