如何从数据库中检索radiobutton值到radiobutton [英] how to retrieve radiobutton value from database to radiobutton

查看:84
本文介绍了如何从数据库中检索radiobutton值到radiobutton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii,



如何从数据库检索radiobutton值到radiobutton



例如:



类型:1。一般2.预留

i hav两个radiobuttons如上所示。

如果存储类型一般是数据库然后一般Radiobutton将检查,反之亦然。



如何检索这个..



感谢先进的

Hii,

how to retrieve radiobutton value from database to radiobutton

example:

Type: 1. General 2. reserve
i hav two radiobuttons as show above.
If type general is stored is database then "General" Radiobutton will check or vice versa.

How to retrieve this..

Thanks in advanced

推荐答案

假设您拥有如下的radiobuttonlist控件: -



Let say you have the radiobuttonlist control as follows :-

<asp:RadioButtonList ID="rbl" runat="server">
            <asp:ListItem Text="General" Value="1"></asp:ListItem>
            <asp:ListItem Text="Reserve" Value="2"></asp:ListItem>
        </asp:RadioButtonList>





现在你可以这样做按照以下两个步骤进行如下所述: -



i)假设您从DB获得的值为'1',即'General'。



然后按下面的值获取ListItem -





Now you can do this in two steps as described below :-

i) Assuming you got the value as '1' from DB which is 'General'.

Then get the ListItem by the value you have as below -

ListItem item = rbl.Items.FindByValue("1");





我们可以传递我们从数据库获取的适当值,而不是在这里传递字符串1。此外,如果您从数据库获取文本,如常规,那么您可以在这里使用'FindValueByText'方法。



ii)现在我们可以设置第二步通过在radiolist中设置此项目的选定索引来选择索引,如下所示: -





We can pass the appropriate value which we are getting from database rather than passing the string "1" here. Also if you are getting the text from database like "General" then you can use the method 'FindValueByText' here.

ii) Now in the second step we can set the selected index by setting the selected index of this item in radiolist as below :-

rbl.SelectedIndex = rbl.Items.IndexOf(item);







希望这对您有所帮助。




Hope this will be of help for you.


这篇关于如何从数据库中检索radiobutton值到radiobutton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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