Click here to Skip to main content
15,922,015 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
Posted
Updated 19-Mar-14 19:35pm
v2
Comments
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

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



:::IN CODE BEHIND:::


C#
protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                FillControls();
            }
            catch (Exception ex)
            {
            }
        }

        private void FillControls()
        {
            try
            {
                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;
                grdDetails.DataBind();

            }
            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
 
v2

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