Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

radiobutton list selected from db

Status
Not open for further replies.

IndyGill

Technical User
Jan 15, 2001
191
GB
OK..... im just feling a bit lost with this one and it seemed like a small and simple task... but i was so wrong.

I have a datagrid which has field which is a boolean. I populate the datagrid fine, but when the user goes to edit that row in the datgrid I would like the boolean field to be shown as a radiobutton list.

So i have created two options in my radiobutton list as below:

<edititemtemplate>
<asp:RadioButtonList id="rbl1" runat="server">
<asp:ListItem Value="1">Yes</asp:ListItem>
<asp:ListItem Value="0">No</asp:ListItem>
</asp:RadioButtonList>
</edititemtemplate>

However I would like the boolean value to be represented in the radiobutton list as the slected button. So if my db has a value of one then Yes will be selected in radio button list.

So I thought I would create a function to get me the value and return a boolean value to the list item. Something like the below:

<asp:ListItem Value="1" Selected="<%#BuildRadioBtns(DataBinder.Eval(Container.DataItem, "SvpaRequired"))%>">Yes</asp:ListItem>

My function is:
Protected Function BuildRadioBtns(ByVal bln As Boolean) As Boolean
If bln = True Then
Return True
Else
Return False
End If
End Function


However this doesnt work, am i going about this the right way? I keep get the below error:

Literal content ('<asp:ListItem Value="1" Selected="') is not allowed within a 'System.Web.UI.WebControls.ListItemCollection'.

Any help would be much appreciated, thanks in advance

 
Lokks like the BuildRadioBtns doesn't return the right value, probably because the value passed to it is not correct? Try this(to make sure you pass a boolean value):
Code:
<asp:ListItem Value="1" Selected='<%#BuildRadioBtns(Convert.ToBool(DataBinder.Eval(Container.DataItem, "SvpaRequired")))%>'>Yes</asp:ListItem>
Notice the single quotes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top