空值的单选按钮列表数据绑定问题 [英] Radio button list databind problem for null values

查看:81
本文介绍了空值的单选按钮列表数据绑定问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我在几个星期内就遇到了这个问题.我有一个带有单选按钮列表的表单1.Active 2.Inactive作为列表项.
在另一页中,我具有dataformview来搜索和编辑上面填充的数据.如果用户在提交过程中未从单选按钮列表中选择任何选项,并尝试在表单视图中编辑空数据,则会引发错误,指出"RadioButtonList"的SelectedValue无效,因为它不存在于项目列表中.我应该解决这个问题.我正在使用varchar作为单选按钮的数据类型.另外哪种数据类型最适合单选按钮(保存数据并绑定).我是否需要为单选按钮列表设置默认值?请帮我.感谢您的回应.
这是单选按钮提交的示例代码

Hey guys, I have this problem from few weeks. I have a form with radio button list 1.Active 2.Inactive as list items .
In another page I have dataformview to search and edit above filled data. If user did not select any option from the radiobutton list during submission and tries to edit null data in form view it throws an error saying "RadioButtonList'' has a SelectedValue which is invalid because it does not exist in the list of items" .How should I approach for this problem. I am using varchar as datatype for radiobutton. Also which datatype would be best for radiobutton (to save data and bind).Do I need to set default value for radiobutton list? Please help me. Appreciate your response.
Here is the sample code of radiobutton submission

<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True"

                   onselectedindexchanged="RadioButtonList1_SelectedIndexChanged"

                   style="text-align: left; font-size: medium;" RepeatDirection="Horizontal"

                   RepeatLayout="Flow" AppendDataBoundItems="True">
                   <asp:ListItem Text="Active">Active</asp:ListItem>
                   <asp:ListItem Text = "Inactive">Inactive</asp:ListItem>



这是formview编辑项目模板的代码



Here is the code for edit item template of formview

<asp:RadioButtonList ID="RadioButtonList3" runat="server"

                            SelectedValue = '<%# Bind("stat") %>'

                            Width="300px" TabIndex="3">
                            <asp:ListItem Text="Active" />

<asp:ListItem Text="Inactive" />



笔记; stat是单选按钮列表的列名.



Note; stat is the column name for radiobutton list

推荐答案

在访问服务器端代码之前使用JavaScript验证....
employ javascript validation before heading to server side code....


这篇关于空值的单选按钮列表数据绑定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆