Toars I will smile to the world ^o^

15Nov/100

(3/3) ListView events, ItemEditing, ItemCanceling, ItemUpdating


Edit Record

Same for this Edit Record, Save Record and Cancel button click events.

Wire the events in the code-behind first.

LstItems.ItemEditing += new EventHandler<ListViewItemEventArgs>(LstItems_ItemEditing); LstItems.ItemUpdating += new EventHandler<ListViewItemEventArgs>(LstItems_ItemUpdating); LstItems.ItemCanceling += new EventHandler<ListViewItemEventArgs>(LstItems_ItemCanceling);

Button "Edit" click.

protected void LstItems_ItemEditing(object sender, ListViewItemEventArgs e) { var item = LstItems.Items[e.NewEditIndex]; // Save the currently selected item to OldDnsRecord
// ReBind the ListView }

Button "Save" click.

protected void LstItems_ItemUpdating(object sender, ListViewItemEventArgs e) { if (!Page.IsValid) return; var txtNewHost = e.Item.FindControl<TextBox>("TxtNewHost"); var txtNewPointsTo = e.Item.FindControl<TextBox>("TxtNewPointsTo"); var ddlNewTtl = e.Item.FindControl<DropDownList>("DdlNewTTL"); var host = txtNewHost.Text; var pointsTo = txtNewPointsTo.Text; var ttl = ddlNewTtl.SelectedValue; var result = UpdateExistingRecord(); if (result == Status.Ok) { LstItems.EditIndex = -1; // Rebind the ListView } else { // Do error handling } }

Button "Cancel" click.

protected void LstItems_ItemCanceling(object sender, ListViewItemEventArgs e) { LstItems.EditIndex = -1; // Rebind the ListView }
Filed under: .NET, C# Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.