Controling the 'selected' property on CheckBoxList while DataBinding()

  • Thread starter Eran Dvey-Aharon
  • Start date
E

Eran Dvey-Aharon

Hi Group!

When binding the CheckBoxList control, you can only control the 'text'
and 'value' properties of each CheckBox created.

Suppose I have on the data source some additional information for the
'checked' initial state, and I want to update the 'selected' property
of each checkbox.

If the data source is static, it seems easy - just iterate over the
data source once again after all items are crated (onDataBound for
instance), and update the 'selected' state.

This is the WRONG approach, because it requires itterating over the
data source once again, and assuming that we got the same result at
the same order.
Working in ASP 2.0 with DataSourceID makes it much harder to implement
(I couldn't write working version).

I'd like to override the exact place where each checkbox item is
created, having a single datasource "row" (or enumerated single
object), and use the Eval syntax to set the selected property from the
data "row".
This is similar to understanding what happens in
OnDataBinding(EventArgs e) on that object.

Any ideas?

Eran Dvey-Aharon
 
I

IronYuppie

This one should help you:

http://msdn.microsoft.com/library/d...ef/html/cpconcheckboxlistwebservercontrol.asp

Write a function to set a given item to true or false based on its value...

<asp:CheckBoxList id="CheckBoxList1"
AutoPostBack="True|False"
CellPadding="Pixels"
DataSource='<% databindingexpression %>'
DataTextField="DataSourceField"
DataValueField="DataSourceField"
RepeatColumns="ColumnCount"
RepeatDirection="Vertical|Horizontal"
RepeatLayout="Flow|Table"
TextAlign="Right|Left"
OnSelectedIndexChanged="OnSelectedIndexChangedMethod"
runat="server">

<asp:ListItem value="value"
selected="True|False">
Text
</asp:ListItem>

</asp:CheckBoxList>
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top