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

Discussion in 'ASP .Net Building Controls' started by Eran Dvey-Aharon, Feb 7, 2005.

  1. 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
    Eran Dvey-Aharon, Feb 7, 2005
    #1
    1. Advertising

  2. Eran Dvey-Aharon

    IronYuppie Guest

    RE: Controling the 'selected' property on CheckBoxList while DataBindi

    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>


    "Eran Dvey-Aharon" wrote:

    > 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
    >
    IronYuppie, Feb 18, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JD
    Replies:
    5
    Views:
    11,608
    NetArchitect
    Aug 8, 2007
  2. Replies:
    0
    Views:
    421
  3. Patrick.O.Ige
    Replies:
    5
    Views:
    19,059
    Patrick.O.Ige
    Jun 19, 2005
  4. Piotr Strycharz
    Replies:
    0
    Views:
    369
    Piotr Strycharz
    Oct 18, 2006
  5. Cheryl Hamm

    Problem with selected property of checkboxlist

    Cheryl Hamm, Dec 28, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    120
    Cheryl Hamm
    Dec 28, 2003
Loading...

Share This Page