怎么将gridview中checkbox的值update到数据库中啊???
//更新protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
sqlcon = new SqlConnection(strCon);
CheckBox chk = (CheckBox)row.FindControl("ShowCheckBox");
string sqlstr = "update GuestInfo set Name='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text.ToString().Trim() + "',Content='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "',Show='"
+ ((CheckBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Bool.ToString().Trim() + "' where id='"
+ GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
sqlcom = new SqlCommand(sqlstr, sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
GridView1.EditIndex = -1;
bind();
}
前台页面
<Columns>
<asp:BoundField DataField="Name" HeaderText="宾客姓名" >
<ItemStyle Width="90px" HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Content" HeaderText="留言内容" >
<ItemStyle Width="130px" />
</asp:BoundField>
<asp:TemplateField HeaderText="显示">
<ItemTemplate>
<asp:CheckBox ID="ShowCheckBox" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="编辑" ShowEditButton="True" />
<asp:CommandField HeaderText="删除" ShowDeleteButton="True" />
</Columns>
红字处怎么解决啊 求教 --------------------编程问答-------------------- http://www.cnblogs.com/eddie005/archive/2006/08/28/488507.html --------------------编程问答-------------------- + ((CheckBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Bool.ToString().Trim() + "'
红字中Bool改成checked试试验 --------------------编程问答-------------------- 选中为值为1,否则值为0
--------------------编程问答-------------------- 存为bool --------------------编程问答-------------------- ((CheckBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Bool.ToString().Trim()
取出控件来判断
((CheckBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Checked == true ? true : false;
如果字符串就加引号 数字就改成1和0
...).Checked == true ? 1: 0;
补充:.NET技术 , ASP.NET