checkboxlist and datavaluefield

G

Guest

Hi,

Is there anyway to get the datavaluefield from a databound checkboxlist
using javascript?

If not, is there any way to associate a custom attribute with the databound
checkboxlist items so that the custom attribute can be accessed using
javascript?

Cheers
 
B

billmiami2

As an alternative, hidden controls can be used to store these
parameters so that they can be easily picked up with client side code.

Bill E.
 
E

Eliyahu Goldin

Is there anyway to get the datavaluefield from a databound checkboxlist
using javascript?
If you mean getting the name of the field on client side, the answer is no.
If not, is there any way to associate a custom attribute with the databound
checkboxlist items so that the custom attribute can be accessed using
javascript?
Sure. ListItem has Attributes property. That's where you can put any
attribute.

Eliyahu
 
G

Guest

Thanks for the suggestions...

I've tried adding a custom attribute to the ListItems by iterating through
all the ListItems after the CheckBoxList has been databound and adding a new
custom attribute that holds the DataValueField value for each ListItem.

However, looking at the html when the CheckBoxList is rendered, the
individual html checkbox input controls that the CheckBoxList becomes do not
have the custom attribute I added. Perhaps I am doing something wrong or
adding the custom attributes at the wrong time...I'm adding them in Page_Load
when it is not a postback, that is, the first time the page is accessed.

As for the hidden input controls approach, I'm not entirely sure how I would
link the hidden controls to the individual html checkboxes that are
rendered...I can dynamically add a bunch of hidden controls which hold the
DataValueField values for each ListItem...but how do I tell which hidden
input control refers to which html checkbox control? I guess one way around
this would be to try to add a custom attribute to the hidden controls to hold
the id of the checkbox that each one refers to.

I guess my problem is that when the CheckBoxList is rendered into individual
html checkbox inputs, those checkbox inputs only have id, name and checked
attributes on client-side and lose their mapping to the data the CheckBoxList
was bound to.

I'm trying to get the DataValueField on client-side because I'm trying to
implement a client-side validation function on the CheckBoxList items...so
when a user checks a particular CheckBoxList item, the validation should
check that a bunch of other controls are completed. The server-side
validation for this is working fine so maybe I'll just leave it as a
server-side only validator.

Cheers again, Dune
 
Joined
Jan 9, 2008
Messages
1
Reaction score
0
Well this is quite old but I'm posting for the sake of those searching for an answer (as I was).
The simple solution to this problem is simple to manually make your own "CheckBoxList" by using a repeater. I simple use html checkbox with runat=server tags.

Here's an examaple:

Code:
<asp:Repeater runat="server" ID="fooChecksRepeater">
<HeaderTemplate>
	<table border="0">
</HeaderTemplate>
<ItemTemplate>
	<tr>
		<td>
		<input type="checkbox" runat="server" id="fooCheck" value='<%# Eval("fooId") %>' /><asp:Literal runat="server" ID="fooLit" Text='<%# Eval("fooName") %>'></asp:Literal>
		</td>
	</tr>
</ItemTemplate>
<FooterTemplate>
	</table>
</FooterTemplate>
</asp:Repeater>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top