1
我正在創建一個網站,我們的客戶可以直接向我們訂購部件。我有一個數據表設置,當用戶點擊一個按鈕時,它向GridView添加訂單的快速細節。在gridview中,我啓用了編輯和刪除按鈕。刪除功能工作正常,但是當您嘗試編輯信息時,它不會更改新信息的網格視圖。這是我到目前爲止:GridView編輯綁定到Datatable時
protected void griditems_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
DataTable dt = (DataTable)Session["table"];
foreach (DataRow dr in dt.Rows)
{
part = Convert.ToString(dr["Part"]);
dr["Part"] = part;
dr["Quantity"] = qty;
dr["Ship-To"] = shipto;
}
griditems.EditIndex = -1;
BindData();
}
當試圖這,它顯示gridview回原始輸入值。我也試過這種(不工作,並得到一個錯誤,指出「目前在位置0無行」:
DataTable dt = (DataTable)Session["table"];
GridViewRow row = griditems.Rows[e.RowIndex];
dt.Rows[row.DataItemIndex]["Part"] = ((TextBox)(row.Cells[1].Controls[0])).Text;
dt.Rows[row.DataItemIndex]["Quantity"] = ((TextBox)(row.Cells[2].Controls[0])).Text;
dt.Rows[row.DataItemIndex]["Ship-To"] = ((CheckBox)(row.Cells[3].Controls[0])).Checked;
griditems.EditIndex = -1;
BindData();
我是在aspx文件缺少EditItemTemplate
,還是我只是做RowUpdating
都錯了?
謝謝!!!我有花了太多的時間才找到一個簡單的解決方案,在幾分鐘內,在你的幫助下!! –
很高興我能夠幫助你......你可能要將它標記爲答案?... :) – NiK