간만에 포스팅 합니다. 한 오백만년은 된 듯합니다. ㅋㅋㅋ

요즘엔 asp.net 을 가지고 맨땅에 헤딩하느라 고생이 이만 저만이 아니네요... ㅋㅋㅋ
전 winform 개발자이고 싶은데 말이죠... 푸헤헤

여튼 Bug 라고 공식적으로 알려진 사항인데 저는 이제야 알았네요...

내용은 이렇습니다.

Repeater 나 ListView Server Control 의 itemTemplate 에 RadioButton 을 추가하게 되면 grouping 을 할 수 없습니다.

이유인 즉은 iNamingContainer 인터페이스를 구현하는 녀석들이라서라고 하네요.

iNamingContainer 인터페이스의 특징은 item Template 내부에 추가되는 컨트롤들은 고유의 name 속성을 가져야하는 데...

아시다 시피 radio 버튼을 Group으로 묶어 주기 위해서는 아래와 같이 name 속성을 동일하게 해야햐죠?

<input id="Radio1" type="radio" name="1" />
<input id="Radio2" type="radio" name="1" />
<input id="Radio3" type="radio" name="1" />
<input id="Radio4" type="radio" name="1" />
<input id="Radio5" type="radio" name="1" />


그런데 iNamingContainer 인터페이스 를 구현하는 녀석들은 name 속성이 고유하게 생성이 되서 Group 으로 묶이지 않는 것이었습니다.
asp.net RadioButton 서버컨트롤이 가지고 있는 GroupName 이라는 속성을 주더라도 소용이 없는 거죠... ㅋㅋ

아래의 Repeater 나 ListView 가
        <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                <asp:RadioButton id="RadioButton1" runat="server" GroupName="RB" Text="<%#Container.DataItem.ToString()%>">
                </asp:RadioButton><br>
            </ItemTemplate>
        </asp:Repeater>

HTML Tag 로 Rendering 된 모습을 보게되면 아래와 같습니다.
<input id="MainContent_Repeater1_RadioButton1_0" type="radio" name="ctl00$MainContent$Repeater1$ctl00$RB" value="RadioButton1" /><label for="MainContent_Repeater1_RadioButton1_0">Test Value 0</label><br>           
<input id="MainContent_Repeater1_RadioButton1_1" type="radio" name="ctl00$MainContent$Repeater1$ctl01$RB" value="RadioButton1" /><label for="MainContent_Repeater1_RadioButton1_1">Test Value 1</label><br>            
<input id="MainContent_Repeater1_RadioButton1_2" type="radio" name="ctl00$MainContent$Repeater1$ctl02$RB" value="RadioButton1" /><label for="MainContent_Repeater1_RadioButton1_2">Test Value 2</label><br>

name 속성의 값이 모두 다르죠?

이러니 Group 으로 묶을 수 있겠습니까? ㅋㅋㅋ

http://support.microsoft.com/kb/316495/en-us
여기에 버그로 등록이 되어 있네요... 오랜 세월이 흘렀는데도 고쳐지지 않는 것을 보면... 쉽사리 건드리기 힘든 녀석인가 봅니다. 이해가 안가지만요... ㅋㅋ

그래서 해법을 찾아보았습니다. ㅋㅋㅋ

http://www.codeguru.com/csharp/csharp/cs_controls/custom/article.php/c12371/

GroupRadioButton 을 만드신 분도 계시군요...
http://www.codeproject.com/Articles/7960/How-to-group-RadioButtons


행복한 고수되십시요...

반응형

+ Recent posts