Advertisement
Advertisement

新足迹

 找回密码
 注册
新足迹 门户 IT专业论坛 查看内容

小白的C#问题

2011-6-15 11:38| 发布者: porcorosso | 查看: 1266| 原文链接

学C#,碰到问题:

In the Formview, I have a field thats with Checkbox. In the database this column is named 'Status' with Tinyint as datatype. Now, when I show particular item from database to the screen, I do this:
  1. <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Convert.ToBoolean(Eval("status")) %>' />
复制代码
which is fine (but not sure if it is best practise)

The problem is when I like to save. VS generate the code for me as below:
  1. <asp:SqlDataSource ID="SqlDataSource1" runat="server"
  2.             ConnectionString="<%$ ConnectionStrings:testdemoConnectionString %>"
  3.             SelectCommand="SELECT * FROM [test_table_1] WHERE ([id] = @id)"
  4.             DeleteCommand="DELETE FROM [test_table_1] WHERE [id] = @id"
  5.             InsertCommand="INSERT INTO [test_table_1] ([name], [email], [status]) VALUES (@name, @email, @status)"
  6.             UpdateCommand="UPDATE [test_table_1] SET [name] = @name, [email] = @email, [status] = @status WHERE [id] = @id">
复制代码
which is null when the checkbox is untick. instead of having an extra hidden field in the form to mimic this checkbox value as int/string, is there any other way to store this value into database, directly from the form?
Advertisement
Advertisement


Advertisement
Advertisement
返回顶部