本人使用gridview创建了一个check的模板列,还有一个包含主键的隐藏列。为什么这两列都无法取到正确的值,每次取都是空值??????
解决方案 »
- excel导入总是出问题
- 【提问】flash+asp.net文件上传
- SOS...net问题!
- 看看怎么实现这样的效果,最好能把主要代码贴出来(http://www.ppg.cn/YesPPG_CN/Products/NewProductDetail.aspx?ProductGroupID=613&ProductCode=031251204)
- 高分在线等:access绑定datalist的莫名问题
- string如何取字符(从第3到第7位)
- 请教有经验的高手
- 水晶报表无法导出为html,不知何故?100分请教!
- 请问大家有没有像动网一样的论坛代码是用.net做的
- 想要系统学习ado.net有什么好教程
- 如何实现这个方法?
- 页面跳转问题
另外,最好不要用主键隐藏列,而是用DataKeyNames
比如:Label lb = GridView1.Rows[0].FindControl("labelID") as Label;
更新
int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
编辑
int id = Convert.ToInt32(GridView1.DataKeys[e.NewEditIndex].Value);
删除
int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);模板列事件:
Control cmdSource = (Control)e.CommandSource;
GridViewRow gvr = (GridViewRow)cmdSource.NamingContainer;
int rowIndex = gvr.RowIndex;
int id = Convert.ToInt32(GridView1.DataKeys[rowIndex].Value.ToString());//取得ID还有别的方法 比如和 在HTML代码里 让模板列中的BUTTON 按钮的CommandArgument属性和表中的PK值绑定
在模板列中取值也是可以的
-------------------------------------------------------------如果真的想用 this.GridView1.Rows[0].Cells[0].Text; 去找ID值的话
那你隐藏的那列 应该不包括在 列索引内才对你既然把PK列隐藏 是找不到的用我上面给你的方法吧