问题应该是:DataGrid编辑时如何获得复选框的值
代码<asp:TemplateColumn HeaderText ="<center><font color=#ffffff><b>审核</b></font>">
<ItemTemplate>
<asp:CheckBox id="CheckBox1" runat="server" checked='<%# DataBinder.Eval(Container, "DataItem.IsCheck") %>'></asp:checkbox>
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox id="CheckBox1" runat="server" Text="True" checked='<%# DataBinder.Eval(Container, "DataItem.IsCheck") %>'></asp:checkbox>
</EditItemTemplate>
</asp:TemplateColumn>我在DataGrid_Update事件中用string colvalue = ((TextBox)E.Item.Cells[3].Controls[1]).Text;
updateCommand.Parameters["@Check"].Value = colvalue;来取复选框的值,但是提示告诉我“异常详细信息: System.InvalidCastException: 指定的转换无效。
”请问string colvalue = ((TextBox)E.Item.Cells[3].Controls[1]).Text;应该怎么写就可以取得更新后的值呢!

解决方案 »

  1.   


    CheckBox CheckBox1= ((CheckBox )E.Item.FindControl("CheckBox1");
    if( CheckBox1.checked )
    {
          updateCommand.Parameters["@Check"].Value = CheckBox1.value ;
    }
      

  2.   

    string colvalue = ((String)E.Item.Cells[3].Controls[1]).Text;//不应是TextBox类型
      

  3.   

    To: happyjun2000按照你的方法提示:
    编译器错误信息: CS1041: 应输入标识符,“checked”是关键字源错误:行 89:  //Response.End();
    行 90:  CheckBox CheckBox1= ((CheckBox )E.Item.FindControl("CheckBox1"));
    行 91:  if( CheckBox1.checked )   //指这里
    行 92:  {
    行 93:      updateCommand.Parameters["@Check"].Value = CheckBox1.value ;
     
      

  4.   

    OleDbType.VarChar 这里怎么写是表示类型是布尔值呢?