protected void gvBooks_RowCommand(object sender, GridViewCommandEventArgs e) { GridViewRow row = gvBooks.FooterRow; TextBox txtName = (TextBox)row.FindControl("txtftrName"); TextBox txtAuthor = (TextBox)row.Cells[1].FindControl("txtftrAuthor"); TextBox txtQuantity = (TextBox)row.Cells[2].FindControl("txtftrQuantity"); Book book = new Book(); book.Name = txtName.Text; book.Author = txtAuthor.Text; int quants; Int32.TryParse(txtQuantity.Text, out quants); book.Quantity = quants; BookOperation.Add(book); gvBind(); }
protected void gvBooks_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = gvBooks.Rows[e.RowIndex]; //TextBox txtName = (TextBox)row.Cells[0].Controls[0]; Label lblName = (Label)row.Cells[0].FindControl("lblName"); TextBox txtAuthor = (TextBox)row.Cells[1].FindControl("txtAuthor"); TextBox txtQuantity = (TextBox)row.Cells[2].FindControl("txtQuantity"); Book book = new Book(); book.Name = lblName.Text; book.Author = txtAuthor.Text; int quants; Int32.TryParse(txtQuantity.Text,out quants); book.Quantity = quants; BookOperation.UpdateBook(book); gvBooks.EditIndex = -1; gvBind(); }