在RowDeleting事件中,用下面方式无法取到值: protected void Gvpoint_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
{
//用如下方式,得到的是空值
string id = Convert.ToString(Gvpoint.Rows[e.RowIndex].Cells[0].Text);
//用如下方式可以得到第三列或者其它列的值,但得不到第1列的值(第一列是主键)
int index = e.RowIndex;
GridViewRow row = Gvpoint.Rows[index];
string jobId = Server.HtmlDecode(row.Cells[2].Text);
}
代码如下:
...... <asp:CommandField HeaderText="删除" ShowDeleteButton="True" >
<HeaderStyle HorizontalAlign="Center" />
</asp:CommandField>
<asp:CommandField ShowEditButton="True" HeaderText="编辑" />
</Columns>
......
{
//用如下方式,得到的是空值
string id = Convert.ToString(Gvpoint.Rows[e.RowIndex].Cells[0].Text);
//用如下方式可以得到第三列或者其它列的值,但得不到第1列的值(第一列是主键)
int index = e.RowIndex;
GridViewRow row = Gvpoint.Rows[index];
string jobId = Server.HtmlDecode(row.Cells[2].Text);
}
代码如下:
...... <asp:CommandField HeaderText="删除" ShowDeleteButton="True" >
<HeaderStyle HorizontalAlign="Center" />
</asp:CommandField>
<asp:CommandField ShowEditButton="True" HeaderText="编辑" />
</Columns>
......
解决方案 »
- 关于回发后,绑定的数据清空的问题。
- 谁可以帮忙解释一下!关于刷新回发的!
- 关于SLQ字段提取问题!
- 未能加载文件或程序集“Spring.Core"或者它的依赖项,找到的程序集清单定义与程序集引用不匹配。
- 为什么DropDownList获取的总是第一行的值
- IIS 5.0 连接超时默认是 900 秒啊,怎么连一分钟都没就自己销毁了。
- dropdownlist绑定到一个数据源,怎么样在他的显示上多加一项我动态给定的东西
- {0;d}怎么不好使了?
- weblogic7.0连接池配置,和数据源配置(数据库oracle8.0.0.5)求救
- 我在窗口中添加了一textbox控个,在网页load的时,将textbox赋值为0,现在有一个这样的问题,就是我自己输入的数据,单击添加时,textbox
- 邮件群发提示信息??
- 为什么要特意将SQLHelper类定义为abstract?
然后用Gvpoin.DataKeys[e.index].value.tostring()就能取到ID值了
用cells不好保险的
一直用這個方法 ,沒出現過什麽問題前臺代碼部分沒看到綁定數據的那幾列,不知道具體情況反正不要寫Visible=false不明白樓主為什麽要用Convert.ToString()
Text本來就是String類型啊
(跟你的問題無關,不用介意)