-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);
}
}
}
}
아무도 도와 줄 수 있습니까?
RadioButton의 GroupName 속성이 어떤 방식으로 작동하지 않는지 설명 할 수 있습니까? 저를위한 매력 같이 작동합니다 (적어도 WebForms를 사용했을 때). 어떤 버전의 ASP.NET WebForms를 사용하고 있습니까 (방금 4.0으로 다시 테스트했습니다) – Mirko
RadioButtonList를 사용해 보셨습니까? 그러면 라디오 버튼 그룹이 만들어집니다. 데이터 소스를 바인딩하기 만하면됩니다. http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.radiobuttonlist.aspx – SCB