티스토리 뷰

Repeater 안에 RadioButton을 넣을 경우.. 실행해보면 다 따로논다. GroupName을 줘도 따로논다. 리피터를 실행 후 소스보기를 클릭해서 보면 각 Row마다 앞에 있는 ctl101.. ctl102.. 이렇게 증가되어 있다. 해결방법은 아래와같이

function SetUniqueRadioButton(nameregex, current) {

    re = new RegExp(nameregex);

    for (i = 0; i < document.forms[0].elements.length; i++) {

        elm = document.forms[0].elements[i]

        if (elm.type == 'radio') {

            if (re.test(elm.name)) {

                elm.checked = false;

            }

        }

    }

    current.checked = true;

}

  Repeater_ItemDataBound에 아까 만들어 놓은 함수를 등록시켜주면 된다.


protected void rptPortfolios_ItemDataBound(object sender,
                                           RepeaterItemEventArgs e)
{
   if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType
      != ListItemType.AlternatingItem)
      return;
 
   RadioButton rdo = (RadioButton)e.Item.FindControl("RadioButton1");
   string script =
      "SetUniqueRadioButton('Repeater1.*rdoGroupName',this)";
   rdo.Attributes.Add("onclick", script);
 
}

출처 : http://www.codeguru.com/csharp/csharp/cs_controls/custom/article.php/c12371/ASPNET-Tip-Using-RadioButton-Controls-in-a-Repeater.htm
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함