When you use the RadioButtonList Web Server ASP.NET control, if you add custom attributes to an Item, the key-value pairs are not rendered to the result page. Here's a "fixed" version of the RadioButtonList - the one rendering Item attributes.
RadioButonListItemAttributes
Here's the fixed RadioButtonList, the one that actually renders its items attributes (by overriding the Render method and making sure each Item attributes are rendered) :
~~~~~~~~~~~~~~~~~~~~~~~~~
unit aspxDelphiWCL.RadioButonListItemAttributes ;
interface
uses
System.Web.UI, System.Web.UI.WebControls, System.IO, System.Text,
System.ComponentModel;
type
/// <summary>
/// RadioButonListItemAttributes renders List Item attributes
/// </summary>
[ToolboxData('<{0}:RadioButonListItemAttributes runat=server></{0}:RadioButonListItemAttributes>')]
RadioButonListItemAttributes = class(System.Web.UI.WebControls.RadioButtonList)
strict protected
procedure Render(writer: HtmlTextWriter) ; override;
end;
implementation
procedure RadioButonListItemAttributes.Render(writer: HtmlTextWriter) ;
var
strAttributes: string;
j: Integer;
liHtmlTW: System.Web.UI.HtmlTextWriter;
liSW: System.IO.StringWriter;
liSB: System.Text.StringBuilder;
endIndex: Integer;
index: Integer;
fixedHTML: string;
htmlTW: System.Web.UI.HtmlTextWriter;
SW: System.IO.StringWriter;
SB: System.Text.StringBuilder;
begin
SB := System.Text.StringBuilder.Create;
SW := System.IO.StringWriter.Create(SB) ;
htmlTW := System.Web.UI.HtmlTextWriter.Create(SW) ;
inherited Render(htmlTW) ;
fixedHTML := SB.ToString;
liSB := System.Text.StringBuilder.Create;
liSW := System.IO.StringWriter.Create(liSB) ;
liHtmlTW := System.Web.UI.HtmlTextWriter.Create(liSW) ;
j := 0; index := 0;
while (j <= (Self.Items.Count - 1)) do
begin
if (Self.Items[j].Attributes['Visible'] = 'False') then
begin
index := fixedHTML.IndexOf('<tr>', index) ;
endIndex := (fixedHTML.IndexOf('</tr>', index) + '</tr>'.Length) ;
fixedHTML := fixedHTML.Remove(index, (endIndex - index)) ;
end
else
begin
index := (fixedHTML.IndexOf('<input ', index) + '<input '.Length) ;
liSB.Remove(0, liSB.Length) ;
Self.Items[j].Attributes.Render(liHtmlTW) ;
strAttributes := (liSB.ToString + ' ') ;
fixedHTML := fixedHTML.Insert(index, strAttributes) ;
end;
j := j + 1;
end;
writer.Write(fixedHTML) ;
end;
end.
~~~~~~~~~~~~~~~~~~~~~~~~~
Delphi tips navigator:
» How to set the DataSource property to several db-aware controls in one call
« How to handle system time change using Delphi code

