Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class CustomerView : System.Web.UI.Page { Customer aCustomer = new Customer(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { bind(); } } protected void bind() { List<customer> customerList = new List<customer>(); customerList = aCustomer.getCustomerAll(); gvCustomer.DataSource = customerList; gvCustomer.DataBind(); } protected void gvCustomer_SelectedIndexChanged(object sender, EventArgs e) { GridViewRow row = gvCustomer.SelectedRow; string CustID = row.Cells[0].Text; Response.Redirect("CustomerDetails.aspx?StaffID=" + CustID); } protected void gvCustomer_RowDeleting(object sender, GridViewDeleteEventArgs e) { int result = 0; Customer customer = new Customer(); string CustID = gvCustomer.DataKeys[e.RowIndex].Value.ToString(); result = customer.CustomerDelete(CustID); if (result > 0) { Response.Write("<script>alert('Customer Remove Sucessfully');</script>"); } else { Response.Write("<script>alert('Customer Removal Not Sucessful');</script>"); } Response.Redirect("CustomerView.aspx"); } protected void gvCustomer_RowEditing(object sender, GridViewEditEventArgs e) { gvCustomer.EditIndex = e.NewEditIndex; bind(); } protected void gvCustomer_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { gvCustomer.EditIndex = -1; bind(); } protected void gvCustomer_RowUpdating(object sender, GridViewUpdateEventArgs e) { int result = 0; Customer customer = new Customer(); GridViewRow row = (GridViewRow)gvCustomer.Rows[e.RowIndex]; string id = gvCustomer.DataKeys[e.RowIndex].Value.ToString(); string tCustID = ((TextBox)row.Cells[0].Controls[0]).Text; string tCName = ((TextBox)row.Cells[1].Controls[0]).Text; string tCGender = ((TextBox)row.Cells[2].Controls[0]).Text; string tCDob = ((TextBox)row.Cells[3].Controls[0]).Text; string tCAddress = ((TextBox)row.Cells[4].Controls[0]).Text; string tCTelNo = ((TextBox)row.Cells[5].Controls[0]).Text; string tCEmail = ((TextBox)row.Cells[6].Controls[0]).Text; string tCPassword = ((TextBox)row.Cells[7].Controls[0]).Text; string tMailingList = ((TextBox)row.Cells[8].Controls[0]).Text; string tCUsername = ((TextBox)row.Cells[9].Controls[0]).Text; result = customer.CustomerUpdate(tCustID, tCName, tCGender, tCDob, tCAddress, tCTelNo, tCEmail, tCPassword, tMailingList, tCUsername); if (result > 0) { Response.Write("<script>alert('Customer updated successfully');</script>"); } else { Response.Write("<script>alert('Customer NOT updated');</script>"); } gvCustomer.EditIndex = -1; bind(); } protected void btn_AddNewCustomer_Click(object sender, EventArgs e) { Response.Redirect("CustomerInsert.aspx"); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)