954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

checkbox as a itemtemplate in a datalist

hii every one,
i have an application containing data list.
datalist contains radio button as item template.i want only one radio button to be checked ie when the user clicks on one checkbox the other checkboxes should be unchecked.i have used groupname ,but no use .can any one give the solution to this problem.

greeny_1984
Posting Whiz
372 posts since Apr 2007
Reputation Points: 25
Solved Threads: 29
 

well, you can use checkboxlist but it doesn't work like radio buttons do. The user will be able to select multiple ones if you choose checkboxes instead of radio buttons. But if you decide to do checkboxes, use javascript to uncheck the other boxes in your group.

<script type="text/javascript">
function selectChkBox(field,checkit)
{
  for (i = 0; i < field.length; i++) {
	field[i].checked = false;
  }
  checkit.checked = true;
}
</script>

then call it with an OnClick event like below:

<label><input type="checkbox" id="chkSelection" name="checkbox3" value="3" onclick="javascript:selectChkBox(document.formname.chkSelection,this.name)" />Checkbox 3</label>

I haven't tested it, but it should work. What it does is set all the checkboxes to unchecked, then checks the corresponding checkbox found by its name. Make sure that all your checkboxes are one ID (that are affected anyway), and then have each one a different name.

SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
 

hii,
i have found the solution to this problem.The problem and solution to this issue is very well addressed in the following two articles.
hope this helps others,

http://aspnet.4guysfromrolla.com/articles/122602-1.aspx

http://www.codeproject.com/aspnet/How_group_RButtons.asp?msg=1188105

greeny_1984
Posting Whiz
372 posts since Apr 2007
Reputation Points: 25
Solved Threads: 29
 

thanks greeny.it is really very useful 4 me.

tamannashah
Newbie Poster
1 post since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You