How do i: On DataGrid Row Selection, Change a value in Specific Field using Code

Hi, There's probably a very simple answer to this one but cant find it anywhere!

I have a Data Grid Listing Incidents that have been posted by other users of a site. Fields include IncidentID, IncidentPoster, IncidentTimeDate, IncidentText, IncidentChecked, IncidentCheckedTimeDate

I want a manager to be able to click select on a Row and the Field "IncidentChecked" to be changed from False to True, and also in "IncidentCheckedTimeDate" a Timestamp to be entered into the database. The DataGrid already shows all Rows that have IncidentChecked as False so he should be able to Click through them to Confirm all entries.

Is there an easy method of editing data programatically without using the DataGrids Edit Mode and having the user enter it in manually?

Thanks in advance.

8/30/2007 12:12:07 PM 16182 articles. 0 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 58

Look into RowCommand event.  This will allow you to get the row that is clicked, then you can just find the control for that row and update it.


8/30/2007 6:55:09 PM


Is there an easy method of editing data programatically without using the DataGrids Edit Mode

Based on my knowledge, beside the method you mentioned, there are another two ways to achieve. Both two methods need to put your own controls like checkbox and textbox in the DataGrid control. See the code-behind code:

// Method 1: Loop the items in DataGrid and find the controls
//           in each item.             

 for (int i = 0; i < this.DataGrid1.Items.Count; i++) {


// Method 2: Use the ItemDataBound event of DataGrid.

  protected void ItemDataBound(object sender, DataGridItemEventArgs e)
        this.Label2.Text += e.Item.Cells[0].Text;

Hope that helps. Thanks.

Michael Jin.
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
9/3/2007 3:32:52 AM

Many thanks guys, this was achieved (quite a while back now!). I used the row command event to trigger an SQL query that updated these fields in the database, and then refreshed the page.


8/14/2008 12:55:38 AM