Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Comments
Thanks7872 19-May-14 8:53am    
Have Radiobuttonlist with Values. Store only values in DB. At the time of retrieving it, set list's Selectvalue property to one you got from DB.

If you have Radiobuttons, you should check in code which value you got. Based on that set corresponding button's Checked property to true.
Was that so hard? Try something before posting something.

1 solution

Let say you have the radiobuttonlist control as follows :-

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


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 -

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


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 :-

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



Hope this will be of help for you.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900