私は、グループ名のプロパティとともに、グループのラジオボタンにしようとしています。.. ..ラジオボタンのグループ化のasp.net
をレンダリングしながら、それは私がRadioButtonコントロールを継承しようとしたので、asp.netでの命名規則の仕事をdoesntのそしてオーバーライドラジオボタンと..
を自分のコントロールを作成し、それがグループ化の問題を解決しますが、そのいくつかの理由でビューステートの世話をしていない... ので、すべての私のラジオボタンは、ビューステートレスされている。..
ここに私ですコード:
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