Edit: Updated to support both AutoPostBack and non-AutoPostBack scenarios
Replace with what? Are you going to show some sort of image instead of RB? There could be multiple ways of doing it and the impact is then on implementation of RenderItem and possibly overriding LoadPostdata and perhaps registering some script to accomplish it. For example writing the text and value of ListItem into custom attribute on DIV element and then setting into hidden field with javascript (hidden field named based on the index of the ListItem that was clicked and value then it's value). The plumbing could also be helped in how you put it to pass the valöues tpo the server. For example one hack:
public class MyRadioButtonList : RadioButtonList
{
private string HiddenValueFieldName
{
get
{
return this.ClientID + "_theValue";
}
}
private string DivArrayName
{
get
{
return this.ClientID + "_theDivs";
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
string script = "";
script += "function setValue(theDiv){";
script += "document.getElementById('" + HiddenValueFieldName + "').value = theDiv.getAttribute('value');";
if(this.AutoPostBack)
script += Page.ClientScript.GetPostBackEventReference(this, "", false);
else{
script += "theDiv.style.backgroundColor='gray';";
script += "for(i=0;i<" + DivArrayName + ".length;i++){";
script += "var theVal=" + DivArrayName + "[i];";
script += "if(theDiv.getAttribute('id') != theVal)";
script += "document.getElementById(theVal).style.backgroundColor='white';";
script += "}";
}
script += "}";
Page.ClientScript.RegisterStartupScript(this.GetType(),"setValue",script,true);
//register the hidden field
Page.ClientScript.RegisterHiddenField(HiddenValueFieldName, "");
//register that LoadPostdata will be called even if control's UniqueID is not on post data collection
Page.RegisterRequiresPostBack(this);
//this is playing for the client-side color selection :-)
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach(ListItem litem in this.Items)
{
sb.Append("'");
sb.Append(this.ClientID);
sb.Append(this.IdSeparator);
sb.Append(litem.Value);
sb.Append("'");
sb.Append(",");
}
string s = sb.ToString().TrimEnd(',');
Page.ClientScript.RegisterArrayDeclaration(this.ClientID + "_theDivs", s);
}
protected override bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
{
//wrap the existing loading logic to get the LiostItem value from our hidden field
return base.LoadPostData(HiddenValueFieldName, postCollection);
}
protected override void RenderItem(ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
{
//render the thing out as a DIV
ListItem item=this.Items[repeatIndex];
writer.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, "1px");
writer.AddStyleAttribute(HtmlTextWriterStyle.BorderColor, "black");
writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, "solid");
writer.AddAttribute(HtmlTextWriterAttribute.Value, item.Value);
writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "setValue(this)");
writer.AddAttribute(HtmlTextWriterAttribute.Id, this.UniqueID + this.IdSeparator + item.Value);
if (item.Selected)
writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, "gray");
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.Write(item.Text);
writer.RenderEndTag();
}
}
Note: I just played this out based on my imagination so it *really* might not be what you need but demonstrates the idea. :-)