내 데이터베이스 TextBooks의 테이블에서 바인딩 된 데이터의 Gridview에 편집/업데이트 옵션을 추가했습니다. 관리자가 정보를 수정/업데이트 할 수있는 길을 변경하는 경우이를 허용합니다. 현재 나는 정보에서 편집 유형을 클릭 할 수 있으며 페이지의 현재 그리드에 바인드하지만 데이터베이스에 저장하지 않으며 페이지를 떠나서 돌아 오면 이전 페이지로 되돌아갑니다 값. BindGrid() 메소드에 대한 코드를 따라 한 후에 나는 어딘가 잘못되었지만 그것이 무엇인지를 완전히 파악할 수 없다고 생각한다.업데이트 된 Gridview 행을 데이터베이스 테이블에 저장
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
string query = "select * from textBooks ";
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["HUTDMSConnectionString"].ToString()))
using (SqlDataAdapter adapter = new SqlDataAdapter(query, connection))
adapter.Fill(dt);
ViewState["allBooks"] = dt;
this.BindGrid();
}
}
protected void BindGrid()
{
GridView1.DataSource = ViewState["allBooks"] as DataTable;
GridView1.DataBind();
}
protected void OnRowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
this.BindGrid();
}
protected void OnUpdate(object sender, EventArgs e)
{
GridViewRow row = (sender as LinkButton).NamingContainer as GridViewRow;
string Ancillary = (row.Cells[3].Controls[0] as TextBox).Text;
string BookActive = (row.Cells[4].Controls[0] as TextBox).Text;
string InactiveDate = (row.Cells[6].Controls[0] as TextBox).Text;
string Author = (row.Cells[7].Controls[0] as TextBox).Text;
string Publisher = (row.Cells[8].Controls[0] as TextBox).Text;
string EditionAndDate = (row.Cells[9].Controls[0] as TextBox).Text;
string Imprint = (row.Cells[10].Controls[0] as TextBox).Text;
string eISBN = (row.Cells[13].Controls[0] as TextBox).Text;
string ebookAvailable = (row.Cells[14].Controls[0] as TextBox).Text;
string Notes = (row.Cells[15].Controls[0] as TextBox).Text;
DataTable dt = ViewState["allBooks"] as DataTable;
dt.Rows[row.RowIndex]["Ancillary"] = Ancillary;
dt.Rows[row.RowIndex]["BookActive"] = BookActive;
dt.Rows[row.RowIndex]["InactiveDate"] = InactiveDate;
dt.Rows[row.RowIndex]["Author"] = Author;
dt.Rows[row.RowIndex]["Publisher"] = Publisher;
dt.Rows[row.RowIndex]["EditionAndDate"] = EditionAndDate;
dt.Rows[row.RowIndex]["Imprint"] = Imprint;
dt.Rows[row.RowIndex]["eISBN"] = eISBN;
dt.Rows[row.RowIndex]["ebookAvailable"] = ebookAvailable;
dt.Rows[row.RowIndex]["Notes"] = Notes;
ViewState["allBooks"] = dt;
GridView1.EditIndex = -1;
this.BindGrid();
}
정직하게 내가하고있는 일에서 잃어 버렸습니다. 그저 Update 메소드에서 해당 페이지를 읽었고 내가 가지고있는 것과 정확히 통합하는 방법을 보지 못했습니다. – frostyBolt