Implement Single-choice in repeater (repeater radiobutton)

Source: Internet
Author: User

Method 1: Use the server-side control radiobutton

First, set the autopostback attribute of radiobutton to true. The repeater binding code should be placed in the ispostback of pageload;
Second, save the selected information in radiobutton's checkedchanged.
Finally, in the itemdatabound event of repeater, determine which one was selected last time (this can be done after selection, that is, save the selected information to viewstate in the selectchange event of radiobutton ), then select this radiobutton.
======
The above process is: when the page is loaded, repeater is bound. In this case, no radiobutton is selected (you can also select it, but you need to provide the content of the information to be selected ), then, when radiobutton is selected, it will automatically send back and trigger the checkedchanged event. In the checkedchanged event, you need to mark the unique marker of the selected option, save the tag. For example, there are five rows in total with IDs ranging from 1 to 5. In this checkedchanged event, if radiobutton is selected, the ID is recorded to viewstate. Finally, bind the repeater. Binding of repeater triggers the onitemdatabound event. In this event, we need to traverse all radiobutton and check that the unique tag of radiobutton is the unique tag you recorded (that is, the information saved in viewstate ), if it matches the information you saved, set the radiobutton checked to true; otherwise, set false.
In this way, the radiobutton in repeater can be implemented by single choice.

Method 2: Use JS

Http://topic.csdn.net/t/20050622/08/4098124.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.