通过从数据库中获取值来检查/取消选中gridview中的复选框 [英] check/uncheck checkbox in a gridview by fetching the value from database
问题描述
大家好
我的数据库表中有2列
name value
a 0
b 0
c 0
d 0
所以现在我想要的是如果值为0然后取消选中复选框,当用户选中复选框时,值应更新为1
请告诉我如何获取数据并更新复选框。 />
第一次我必须从database.later加载默认值时,用户将更新并保存。
这是我的数据网格
< my:DataGrid 名称 = dgProducts AutoGenerateColumns = False Grid.Row = 1 Grid.RowSpan = 3 Grid.ColumnSpan = 2 CanUserAddRows = < span class =code-keyword> False >
< my:DataGrid.Columns >
< my:DataGridTextColumn 标题 = 名称 Binding = < span class =code-keyword> {Binding Path = ProductName} 宽度 < span class =code-keyword> = 300 / >
< my:DataGridTemplateColumn >
< my :DataGridTemplateColumn.Header >
< CheckBox 内容 = 可见 点击 = CheckBox_Click Name = CheckBox1 / >
< / my:DataGridTemplateColumn.Header >
< my:DataGridTemplateColumn.CellTemplate >
< DataTemplate >
< CheckBox 名称 = chkDiscontinue IsChecked = {Binding Path = Discontinue,Mode = TwoWay} 保证金 = 45 2 0 0 单击 = chkDiscontinue_Click / >
< / DataTemplate >
< / my :DataGridTemplateColumn.CellTemplate >
< / my:DataGridTemplateColumn >
< / my:DataGrid.Columns >
< / my:DataGrid >
谢谢
请阅读我对该问题的评论。
有y你看到了这个:带有wpf复选框的datagrid [ ^ ]?
请使用 SearchBox [ ^ ]。
Write Converter将0或1转换为True或false并与checkBox绑定:
< checkbox content =Visibleclick =CheckBox_Clickname =CheckBox1ischecked ={Bindingpath =value,Converter = {StaticRsource MyConverter}} />
语法可能有所不同,但遵循这个概念。我相信这会对你有所帮助。
随意提问。
Raman Kumar
Hi all
I have 2 columns in my database table
name value
a 0
b 0
c 0
d 0
so now i want is if the value is 0 then the the checkboxes will be unchecked and when user check the checkbox the value should update to 1
Please tell me how to fetch the data and update the checkboxes.
At the first time i have to load the default value from database.later user will update and save.
This is my datagrid
<my:DataGrid Name="dgProducts" AutoGenerateColumns="False" Grid.Row="1" Grid.RowSpan="3" Grid.ColumnSpan="2" CanUserAddRows="False">
<my:DataGrid.Columns>
<my:DataGridTextColumn Header="Name" Binding="{Binding Path=ProductName}" Width="300"/>
<my:DataGridTemplateColumn>
<my:DataGridTemplateColumn.Header>
<CheckBox Content="Visible" Click="CheckBox_Click" Name="CheckBox1" />
</my:DataGridTemplateColumn.Header>
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Name="chkDiscontinue" IsChecked="{Binding Path=Discontinue,Mode=TwoWay}" Margin="45 2 0 0" Click="chkDiscontinue_Click" />
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
</my:DataGrid.Columns>
</my:DataGrid>
Thank you
Please, read my comment to the question.
Have you seen this: datagrid with checkbox in wpf[^]?
Please, use a SearchBox[^].
Write Converter to convert from 0 or 1 to True or false and bind with checkBox:
<checkbox content="Visible" click="CheckBox_Click" name="CheckBox1" ischecked="{Binding" path="value,Converter={StaticRsource MyConverter"}} />
Syntax may be different but follow this concept . I believe this will help you.
Feel Free to ask any question.
Raman Kumar
这篇关于通过从数据库中获取值来检查/取消选中gridview中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!