Reputation: 4296
I am using a repeater with the Item Template of a checkbox. Here's my checkbox template:
<asp:CheckBox runat="server" ID="chkBox" Text='<%# Eval("Text") %>' Value='<%# Eval("Value") %>' />
Now, I know asp checkboxes do not have a value attribute, but I read somewhere that you can put that in there and it will work the same. I'll have to look it up again to see if I read it wrong. However, just in case it is possible to put the custom attribute in there, how do I retrieve it in code behind? I looked at the source after the page is created and there is no attribute in the control that says "value". Any ideas? Thanks.
EDIT:
Here's where I saw you can add the custom attribute:
http://www.daveparslow.com/2007/08/assigning-value-to-aspnet-checkbox.html
Upvotes: 1
Views: 2563
Reputation: 32278
You can retrieve values from your server controls through the attributes collection. In your case,
string s = chkBox.Attributes["Value"];
However, as a suggestion and as my comment states, if you want a valid page, you should change your doc type to HTML 5 and use the data-
annotation on your custom attribute.
Upvotes: 1