posted by 준치 2012. 10. 4. 15:58

오늘은 앙케이트 조사하는 것을 만들고 있었다... 그런데...

디자인을 받았는데 라디오 버튼 리스트 컨트롤을 사용못하고 그냥 각각의 라디오 버튼 컨트롤을

사용하게 되었다.. 디자인을 바꾸려니.. 시간은 걸리고...흠...ㅠㅠ

결국 자바스크립트로 값을 넣게 만들었지만.. 궁금했다... 서버코드에서 그룹명으로 버튼을 가져올수 있을지가..... 그래서 검색 고고씽...

결론은 서버코드에서 라디오 버튼 컨트롤을 찾을수 있었다.

 groupName 에 찾고 싶은 라디오 버튼 컨트롤의 그룹명을 넣으면 된다.

private RadioButton GetSelectedRadioButton(string groupName)

    {

        return GetSelectedRadioButton(Controls, groupName);

    } 

   

    private RadioButton GetSelectedRadioButton(ControlCollection controls, string groupName)

    {

        RadioButton retval = null;

       

        if (controls != null)

        {

            foreach (Control control in controls)

            {

                if (control is RadioButton)

                {

                    RadioButton radioButton = (RadioButton)control;

                    if (radioButton.GroupName == groupName && radioButton.Checked)

                    {

                        retval = radioButton; break;

                    }

                }

                if (retval == null)

                {

                    retval = GetSelectedRadioButton(control.Controls, groupName);

                }

            }

        } return retval;

    }

참고 : http://stackoverflow.com/questions/3654453/get-selected-radio-button-not-in-a-list-in-asp-net

 

궁금해서 시작했지만... 알아두니 좋군...ㅎㅎ

 

오늘도 화이팅~~~^^