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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set RadioButtonList check field

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
US
I have been trying to use a RadioButton in a Datalist, which works for a Checkbox. But the RadioButton doesn't allow only one button to be selected.

This works but when you change the CheckBox to RadioButton - it displays correctly but does not behave as a set of radiobuttons.

Code:
  <asp:DataList ID="lstPermissions" runat="server" RepeatLayout="Flow">
     <ItemTemplate>
	<asp:CheckBox ID="rblPermission" TextAlign="right" runat="server" Text='<%# Eval( "PermissionName") %>'
	  PermissionId='<%# Eval( "PermissionId") %>' Checked='<%# Convert.ToBoolean(Eval( "Assigned")) %>' />
     </ItemTemplate>
  </asp:DataList>

So I changed this to use a RadioButtonList and not the DataList:
Code:
<asp:RadioButtonList ID="rblPermission" TextAlign="right" 
	runat="server" Text='<%# Eval( "PermissionName") %>'
	PermissionId='<%# Eval( "PermissionId") %>' 
	Checked='<%# Convert.ToBoolean(Eval( "Assigned")) %>' />

But I get an error that says I can't use Eval with this so I change it to do the Binding in the Code Behind. But how do I do it so it will do the Checked based on the data recieved? As well as my Attribute (PermissionId)?

Thanks,

Tom
 
If you are binding to a checkboxlist, you will have to loop through your datasource and each rbl item (nested loop) and compare ids, and then check off the items based on that compaison. It will be a manual process, not just a simple .databind().
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top