获取GridView中选中行的单元格内容,单元格明明有内容但是为啥获取的值是空

哇啦哇啦哇咔咔 2020-05-16 11:01:46
就是想给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中那一列是真的有值的
望各位过路大佬指点一二
感谢
...全文
212 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
EdsionWang 2020-05-17
  • 打赏
  • 举报
回复
参考微软官方示例中的代码。 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();
  }

62,039

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧