我很难调试这个奇怪的问题(也许这很奇怪,因为我是第一次做VB.NET的PHP人员)
我有一个如下所示的Gridview
<asp:GridView ID="MyGridViewID" runat="server" AutoGenerateColumns="False"
DataKeyNames="employee_id" DataSourceID="all_employee" >
<Columns>
<asp:BoundField DataField="employee_id" HeaderText="employee_id"
ReadOnly="True" SortExpression="employee_id" Visible="False" />
<asp:BoundField DataField="employee_name" HeaderText="employee_name"
SortExpression="employee_name" />
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<br />
<asp:RadioButtonList ID="RadioPermission" runat="server">
<asp:ListItem Value="1">Yes</asp:ListItem>
<asp:ListItem Selected="True" Value="0">No</asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowSelectButton="True" ItemStyle-CssClass="visibility" ShowHeader="false"
HeaderStyle-CssClass="visibility" >
<HeaderStyle CssClass="visibility" />
<ItemStyle CssClass="visibility" />
</asp:CommandField>
</Columns>
</asp:GridView>
然后我有一个按钮将信息保存到数据库,它与保存部分
配合得很好For Each row As GridViewRow In MyGridViewID.Rows
Dim radio_cp As RadioButtonList = CType(row.Cells(7).FindControl("RadioPermission"), RadioButtonList)
If radio_cp.SelectedValue = 1 Then
' BLOCK A: saving to the db if the radio is YES
Else
' BLOCK B: deleting from the db if the radio is NO.
End If
Next
我的问题:
当我第一次将所有收音机设为NO时加载Gridview,我为某些收音机选择YES并点击保存,效果很好。
然后刷新Gridview,并在这些无线电中正确反映更改。
然后我为当前设置为YES的广播选择NO,然后再次点击Save =&gt; radio_cp.SelectedValue始终返回1.
问题与Checkbox和Radio相同:我无法检测用户何时取消选中checkbox / radio。我认为gridview在某个地方保存了那些checckbox / radio的状态,但我无法弄清楚
我尝试使用EnableViewState没有运气,谷歌搜索也没有运气。
我尝试使用OnCheckedChecked事件,但它无效。
我可能会在这里遗漏一些东西,你能帮忙吗?
感谢您的所有时间!
答案 0 :(得分:0)
你的代码应该有用...... 我根据你的代码编写了一个简单的应用程序,它运行得很好。
我不确定问题究竟在哪里,是否还有其他可能影响radiobuttonlist的内容?
编辑:
这可能对您的问题没有影响,但您可以这样做:
Dim radio_cp As RadioButtonList = CType(row.FindControl("RadioPermission"), RadioButtonList)