如何在GridView中将字符串Empty设置为单选按钮列表 [英] How to set the string Empty to the radiobuttonlist in gridview

查看:70
本文介绍了如何在GridView中将字符串Empty设置为单选按钮列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的应用程序中,我正在使用gridview.在这种情况下,我使用带有两个列表项值"Y"和"N"的单选按钮列表.在我的表单中,我想检查该单选按钮列表的条件.如果为"Y",则选择单选按钮;如果为"N",则将选择该单选按钮.如果为空,则无需选择单选按钮列表.我的问题是,当我绑定数据时,它显示错误,表明存在string.empty单选按钮列表值,但在项目列表中不可用.如何解决这个问题呢.这是代码

Hi,

In my application I am using the gridview. In that I am using the Radiobutton list with two list item value "Y" and "N". In my form I want to check the condition for that radiobutton list. If it is "Y" the radiobutton to be selected and if it is "N" it will be selected. If it is Empty No need to select the Radiobuttonlist. My problem is When I am binding the data it Showing the error that the radiobutton list value is present for string.empty but it is not available in the list of item. How to solve this problem. Here is the code

<asp:TemplateField HeaderText="Status">
                                        <ItemTemplate>
  <asp:RadioButtonList ID="rdbConsultantInvolved" runat="server" CssClass="css_radiobutton_list"

SelectedValue='<%#DataBinder.Eval(Container.DataItem ,"SolutionEngineerConfirmId")%>' RepeatDirection="Horizontal"

AppendDataBoundItems="True">
<asp:ListItem Value="N" Text="Open" ></asp:ListItem>
<asp:ListItem Value="Y" Text="Confirmed"></asp:ListItem>
</asp:RadioButtonList>

                                        </ItemTemplate>
                                        <HeaderStyle HorizontalAlign="center" VerticalAlign="Middle" />
                                        <ItemStyle />
                                    </asp:TemplateField>





谢谢





Thanks

推荐答案



对于您的情况,您应该使用
Hi,

In your case you should use the
OnDataBinding

事件,并手动绑定数据.

或者您可以将其他项目添加到列表中

event, and manually bind your data.

Or you could add another item to your list

<asp:listitem value="" text="" style="display: none" xmlns:asp="#unknown" />

,它将处理数据库中的空值.


希望这会有所帮助.

and it will handle your empty values from database.


Hope this helps.


这篇关于如何在GridView中将字符串Empty设置为单选按钮列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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