2012-05-11 6 views
-1
내가 함께 그룹 이름 속성을 사용하여 그룹의 라디오 버튼에 노력하고

.. 그것은 라디오 버튼 그룹의 asp.net

그래서 내가 상속 라디오 버튼 컨트롤에 시도 .. 때문에 렌더링하는 동안 asp.net의 명명 규칙의 작업을 나던 및 오버라이드 라디오 버튼은 내 자신의 컨트롤을 만들어 ..

그것이 그룹화 문제를 해결하지만 어떤 이유로 viewstate가 돌보는하지 ... 그래서 내 모든 라디오 버튼은 여기

내입니다 .. viewstate가없는있다 코드 :

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Web.UI.WebControls; 
using System.Web.UI; 

namespace CustomControl 
{ 
    public class GroupRadioButton : RadioButton 
    { 
     public GroupRadioButton() 
      : base() 
     { } 

     protected override void Render(HtmlTextWriter writer) 
     { 
      base.Render(new GroupedRadioButtonTextWriter(writer,this.GroupName)); 
     } 
    } 

    public class GroupedRadioButtonTextWriter : HtmlTextWriter 
    { 
     private string groupName; 

     public GroupedRadioButtonTextWriter(HtmlTextWriter baseWriter, string groupName) : base(baseWriter) 
     { 
      this.groupName = groupName; 
     } 

     public override void AddAttribute(HtmlTextWriterAttribute key, string value) 
     { 
      if (key == HtmlTextWriterAttribute.Name) 
      { 
       base.AddAttribute(key, this.groupName); 
      } 
      else 
      { 
       base.AddAttribute(key, value); 
      } 
     } 
    } 
} 

아무도 도와 줄 수 있습니까?

+1

RadioButton의 GroupName 속성이 어떤 방식으로 작동하지 않는지 설명 할 수 있습니까? 저를위한 매력 같이 작동합니다 (적어도 WebForms를 사용했을 때). 어떤 버전의 ASP.NET WebForms를 사용하고 있습니까 (방금 4.0으로 다시 테스트했습니다) – Mirko

+3

RadioButtonList를 사용해 보셨습니까? 그러면 라디오 버튼 그룹이 만들어집니다. 데이터 소스를 바인딩하기 만하면됩니다. http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.radiobuttonlist.aspx – SCB

답변

1

RadioButtonList을 사용해야한다는 사실을 고려하여 나만의 라디오 버튼을 구현하여 시간을 잘못 사용했다고 생각합니다.

+0

버튼이 양식의 다른 위치에 있기 때문에 라디오 버튼 목록에서 문제가 해결되지 않습니다. : 라디오 버튼 그룹화가 여전히 어떤 이유로 작동하지 않습니다. –

관련 문제