C# ASP.NET DataGrid 复选框
我有一个可编辑数据网格,它从 SQL 查询中提取数据,其中一个字段有 Y 或 N 答案,因此需要是一个复选框,但是在编辑模式下,如果我将其放入
<asp:CheckBox ID="ALFSUPR" runat="server" Checked='<%# Bind("pric_c_alfsupreq") %>'></asp:CheckBox>
是否存在, 它会显示为一个字段并出现错误将文本字段转换为复选框的简单方法,选中时有一个值 = Y
谢谢
I have an Editable Data grid which is pulling data from a SQL query one of the field has a Y or N answer and therefore needs to be a checkbox however in Edit Mode it shows as a field and errors if I put this in
<asp:CheckBox ID="ALFSUPR" runat="server" Checked='<%# Bind("pric_c_alfsupreq") %>'></asp:CheckBox>
Is there a simple way of converting the Text Field to a CheckBox which when Checked has a value = Y
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试这样的事情:
更新:
由于您使用的是旧的DataGrid(现在您应该使用DataGridView),所以您应该有类似的东西在您的
DataGrid
定义中:请参阅 OnUpdateCommand...
现在,当您对行数据应用更新时应运行的方法:
希望您明白了。如果您在任何其他时刻需要此代码,您可以将其放置在
OnEditCommand
、OnDeleteCommand
等中...Try something like this:
UPDATE:
Since you're using an old DataGrid (you should be using DataGridView nowadays), you should have something similar to this in your
DataGrid
definition:See the OnUpdateCommand...
Now the method that should run when you're applying an update to the row's data:
Hope you get the idea. If you need this code in any other moment you can place it in the
OnEditCommand
,OnDeleteCommand
, etc...如果您的代码需要比 Simon 的答案更多的逻辑,您还可以在后面的代码中创建一个受保护的方法并调用它。
然后用
If your code requires a bit more logic than Simon's answer, you can also create a protected method in your code behind and call it.
and then call it with
不太记得我的 WebForms 日子,但可能会更改
为
当您更新时,我认为您必须处理 GridView.RowUpdating 事件,然后提取 Checked 属性,将其转换为“是”或“否”。
Can't really remember my WebForms days, but possibly change the
to
When you update, I think you'll have to handle the GridView.RowUpdating event, then extract the Checked property, convert it to "Yes" or "No".