When a user clicks on the "Edit" control, I need to copy the data before the row goes to Edit mode. I am trying GridView_RowCommand Event but I can't assemble the code to copy the row data, or cells in the row, where the Edit control resides. What Event do I use to do this and what code will copy the row that the "Edit" control was in?
![]() |
0 |
![]() |
can u plz explain why do u need to copy row data before going to edit mode?
![]() |
0 |
![]() |
I am working on a way to audit data changes. I'm not sure of the best approach yet so I had to start somewhere. I want to compare old values to new values and if there is a change, Email the comparison to the user. So I figured I would copy the row data before Edit and Copy data after Update and compare the two for any change. I have a sql trigger in place but I'm trying to come up with the best way to get the changes emailed to the user in the best format.
![]() |
0 |
![]() |
I am not very sure, but I think you want to capture the row of a Grid, when a user clicks it.
you can use the SelectedIndexChanging event for that. something like this:
protected void SearchResultsGrid_SelectedIndexChanging(object sender, GridViewSelectEventArgs e){
Label lbId = (Label)SearchResultsGrid.Rows[e.NewSelectedIndex].FindControl("LblData");String Id = lbId .Text;
}
please let me know if this helps.
Ashu Agarwal
Please “MARK AS ANSWER” if my post helped you.
![]() |
0 |
![]() |
as i think u will need to make the comparison after user clicks update button of row. if this is the case then u can do tht thing in RowUpdating event of gridview. In this event, get old value of data of the row programmaticaly in code behind because by tht time row wil not be updated with new values, store these values somewhere. Then get new data from controls in edit mode of gridview row, compare them and then update the row.
![]() |
0 |
![]() |
yes, copy the row, or the data of the row, when a user clicks on the Edit control of that row. That's one of the main issues...is when Edit is clicked, not when Select is clicked. I want to either cache or put in session the values. I think session will be the way to go and I can cancel the session when the compare is completed.
![]() |
0 |
![]() |
I am trying to understand how to get the values when the Edit button is clicked...
![]() |
0 |
![]() |
lbId is a label on the page.? Right? Also, elaborate on String Id. What does it represent?
![]() |
0 |
![]() |
I want to say...ok...if the user clicks Edit on a particular row. What are the values in that row? Take those values and put them somewhere. Then, if the row is updated, compare the new values to the ones that were stored somewhere. If any are different, then put those values somewhere to be stored and emailed. Otherwise, if the user Cancelled the Edit, then disregard the original values that were stored.
![]() |
0 |
![]() |
actually,Lbldata is a column-label on the gridview. In the example, you are getting the value of that column on a dynamic label which is lbId. the value of that label is stored in String Id. following is the example gridview:
<
asp:GridView ID="SearchResultsGrid" runat="server" " AutoGenerateColumns="False" EnableViewState="true" EmptyDataText="--- There are no data ---" EmptyDataRowStyle-Font-Italic="True" SelectedIndex="0"Width="760px" onrowdatabound="SearchResultsGrid_RowDataBound" onselectedindexchanging="SearchResultsGrid_SelectedIndexChanging" PageSize="50" ><PagerSettings Mode="NextPreviousFirstLast" PageButtonCount="20" />
<
EmptyDataRowStyle Font-Italic="True"></EmptyDataRowStyle> <Columns> <asp:TemplateField HeaderText="Address" > <ItemTemplate><%#Eval("Address")%> </ItemTemplate> <HeaderStyle HorizontalAlign="Left" /> <ItemStyle HorizontalAlign="Left" /> </asp:TemplateField><asp:TemplateField HeaderText="" > <ItemTemplate><asp:Label ID="Lbldata " runat="server" Text= <%#Eval("LocId")%> Visible="false" /></ItemTemplate> <HeaderStyle HorizontalAlign="Left" /> <ItemStyle HorizontalAlign="Left" /> </asp:TemplateField> </Columns> </asp:GridView>
Ashu Agarwal
Please “MARK AS ANSWER” if my post helped you.
![]() |
0 |
![]() |