+ -
当前位置:首页 → 问答吧 → GridView 上 CheckBoxField 的 列 text值报错

GridView 上 CheckBoxField 的 列 text值报错

时间:2011-12-26

来源:互联网

<asp:CheckBoxField DataField="AA" HeaderText="查看" /> 这是AA 列的类型.然后,我用下面的方式去取BOOL值.
 model.AA = bool.Parse(((TextBox)this.GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text.ToString());
结果报错,报错如下
无法将类型为“System.Web.UI.WebControls.CheckBox”的对象强制转换为类型“System.Web.UI.WebControls.TextBox”。
请问高人,我的代码应该如何改呢

作者: zhengyingcan   发布时间: 2011-12-26

改为 model.AA = bool.Parse(((TextBox)this.GridView1.Rows[e.RowIndex].FindControl("你的控件ID")).Text);

作者: dalmeeme   发布时间: 2011-12-26