CheckboxList in DataList ?

E

Ed West

Hello

I am trying to put a CheckBoxList in a DataList but it's not working too
great. Is this possible?

<asp:datalist id=DataList1 runat="server" RepeatColumns="4">
<HeaderTemplate>
<asp:CheckBoxList id=states runat=server>
</HeaderTemplate>
<ItemTemplate>
<asp:ListItem Value='<%# DataBinder.Eval(Container.DataItem,
"id")%>'><%# DataBinder.Eval(Container.DataItem, "name")%></asp:ListItem>
</ItemTemplate>
<FooterTemplate>
</asp:CheckBoxList>
</FooterTemplate>
</asp:datalist>

thanks
 
K

Karl

Ed,
Just by looking at your example, why not simply bind to the checkboxlist?

states.DataSource = source
states.DataBind()

?

Karl
 
E

Ed West

Oh yeah, good idea. Didn't know I could do that. I also might want to
set some of the items to checked if a field in the query is checked, can
I do a CheckBoxList1_ItemChanged event or something to set checked=true
if another field in that query row is not null? If so, how can i do
that exactly?

thanks,

-ed
 
K

Karl

There's no simple way, the best is to loop through your datasource and set
the fields..but if you are going to do that, forget the databinding:

for each row as DataRow in DataTable
dim li as new ListItem(row("name"), row("id"))
if row("checked") = true then
li.selected = true
end if
states.Items.Add(li)
next

karl
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top