public List<HttpHeader> CollectFormData(bool includeEmpty) { List<HttpHeader> headers = new List<HttpHeader>(); foreach (GridViewRow row in gvCustomHeaders.Rows) { TextBox txtName = (TextBox)row.FindControl("txtName"); TextBox txtValue = (TextBox)row.FindControl("txtValue"); // create a new HttpError object and add it to the collection HttpHeader header = new HttpHeader(); header.Key = txtName.Text.Trim(); header.Value = txtValue.Text.Trim(); if (includeEmpty || header.Key != "") headers.Add(header); } return headers; }
protected void btnAdd_Click(object sender, EventArgs e) { List<HttpHeader> headers = CollectFormData(true); // add empty error HttpHeader header = new HttpHeader(); header.Key = ""; header.Value = ""; headers.Add(header); gvCustomHeaders.DataSource = headers; gvCustomHeaders.DataBind(); }