就是想給GridView寫個編輯事件 需要獲取當前資料行來進行更新資料庫
資料庫中是有內容的 但是用斷點就是說到那一步的時候 獲取的值為空
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
showMessage();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
showMessage();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string cc = GridView1.Rows[e.RowIndex].Cells[1].Text.Trim();
Model.Message editmess = MessageBLL.GetModel(int.Parse(cc));
editmess.Contents = GridView1.Rows[e.RowIndex].Cells[3].Text;
MessageBLL.Update(editmess);
showMessage();
}
就是上面代碼中的cc 值是空的 但是GridView中那一列是真的有值的

望各位過路大佬指點一二
感謝

uj5u.com熱心網友回復:
參考微軟官方示例中的代碼。https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.gridview.rowupdating?redirectedfrom=MSDN&view=netframework-4.8
protected void TaskGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//Retrieve the table from the session object.
DataTable dt = (DataTable)Session["TaskTable"];
//Update the values.
GridViewRow row = TaskGridView.Rows[e.RowIndex];
dt.Rows[row.DataItemIndex]["Id"] = ((TextBox)(row.Cells[1].Controls[0])).Text;
dt.Rows[row.DataItemIndex]["Description"] = ((TextBox)(row.Cells[2].Controls[0])).Text;
dt.Rows[row.DataItemIndex]["IsComplete"] = ((CheckBox)(row.Cells[3].Controls[0])).Checked;
//Reset the edit index.
TaskGridView.EditIndex = -1;
//Bind data to the GridView control.
BindData();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/39841.html
標籤:ASP.NET
上一篇:OpcDaNet.dll 是32位的,我的C#平臺是64位的,在不改變C#平臺的前提下,如何能正確運行32位的OpcDaNet.dll
