Solved

How to handle edit event with custom code in gridview control?

Posted on 2014-12-19
3
426 Views
Last Modified: 2015-01-05
Hi, I'm using VS2012, C# and asp.net.
I have a collection,  List<UserPrincipal>, that I use as a datasource and binded to the gridview, by code.  In gridview control property I set generate Edit button.  Since the data source is not from a dataset.  How can I have my own code executed when user selects "Update" button in the grid?
Thank you.
0
Comment
Question by:lapucca
  • 2
3 Comments
 
LVL 33

Accepted Solution

by:
Mike Eghtebas earned 500 total points
ID: 40510476
Can you post your code showing how gv update is being done?
0
 

Author Comment

by:lapucca
ID: 40511214
The collection,  List<UserPrincipal> is created and bind to the gridview at PageLoad event and if not PostBack.  
1.  Do I need to persist this collection in a session variable so I can use it to update it later or since it's bind to gridview then I would somehow still have access to this data?
2.  In my Asp.net book, it only show how to use the UpdateCommand to run sql update.  I have custom C# code that I need to run to update to AD.  I haven't written this code yet but basically this is what I need to do.
a.  Get the Userid column data form the data gird or somehow retain which row and the userid of that row that the user is updating when they click the Edit button.
b.  When user click the update button, I need to retrieve the UserPrincipal object in the collection that is being edited and update AD.  (How do I retrieve this object from gridview or do I need to persist this in session?)
Thank you.
0
 

Author Comment

by:lapucca
ID: 40511261
Okay, I found this and that seems to be what I need.  However, I'm not sure how to find the object UserPrincipal in the collection List<UserPrincipal> that is being updated.  So in the event TaskGridView_RowUpdating of this article, it's any array.  Let say I can get the key from userid column of the row that is being edited, how do I find it in the collection?  Thank you.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question