471,073 Members | 1,171 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

CheckboxList in DataList ?

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
Nov 18 '05 #1
3 2792
Ed,
Just by looking at your example, why not simply bind to the checkboxlist?

states.DataSource = source
states.DataBind()

?

Karl

"Ed West" <we**@westville.com> wrote in message
news:uh**************@TK2MSFTNGP12.phx.gbl...
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

Nov 18 '05 #2

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

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

states.DataSource = source
states.DataBind()

?

Karl

"Ed West" <we**@westville.com> wrote in message
news:uh**************@TK2MSFTNGP12.phx.gbl...
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


Nov 18 '05 #3
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

"Ed West" <we**@westville.com> wrote in message
news:es**************@TK2MSFTNGP11.phx.gbl...

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

Karl wrote:
Ed,
Just by looking at your example, why not simply bind to the checkboxlist?
states.DataSource = source
states.DataBind()

?

Karl

"Ed West" <we**@westville.com> wrote in message
news:uh**************@TK2MSFTNGP12.phx.gbl...
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


Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Carl Howarth | last post: by
2 posts views Thread by Patrick.O.Ige | last post: by
4 posts views Thread by Patrick.O.Ige | last post: by
2 posts views Thread by Patrick Olurotimi Ige | last post: by
reply views Thread by Patrick Olurotimi Ige | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.