How to add DataBinded CheckBoxList in Datalist

Discussion in 'ASP .Net' started by =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, Jun 17, 2005.

  1. Is it possible to bind a checkboxlist if this checkboxlist is in a datalist
    Bcos when i add a CheckBoxlist to a Datalist i get :-
    Object reference not set to an instance of an object error at:-
    checkboxlist1.DataSource = myDataSet
    Why?
     
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, Jun 17, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?UGF0cmljay5PLklnZQ==?=

    Jeremy S Guest

    You might try a variation of the code below.
    Basically as each row is DataBound to your DataList, you do whatever you
    must with the controls in your item template. In the code below there is a
    button (btnDeleteThis) to which I'm adding an attribute. I suspect this
    could be easily modified to find your CheckBox list. So, it may be as simply
    as adjusting the following code. Sorry I'm under the gun on a project to
    convert this to VB for you - but it should show you what needs to be done.

    The first line creates a reference to the object (a button in my case, buta
    CheckBoxList in your case) via FindControl.

    If that first line worked (the object reference is not null), then you can
    proceed to databind your CheckBoxlist (inside the IF structure).


    private void MyDataList_ItemDataBound(object sender,
    System.Web.UI.WebControls.DataListItemEventArgs e) {
    Button curButton = (Button)e.Item.FindControl("btnDeleteThis");
    if (curButton != null) {
    curButton.Attributes.Add("onclick", "return confirm('Delete This?');");
    }
    }

    -HTH

    "Patrick.O.Ige" <> wrote in message
    news:...
    > Is it possible to bind a checkboxlist if this checkboxlist is in a
    > datalist
    > Bcos when i add a CheckBoxlist to a Datalist i get :-
    > Object reference not set to an instance of an object error at:-
    > checkboxlist1.DataSource = myDataSet
    > Why?
     
    Jeremy S, Jun 17, 2005
    #2
    1. Advertising

  3. Thx Jeremy but i fixed that earlier using ItemBound.
    But i still have one more issue since the CheckBoxList is Databinded i
    would like to get the selected item but when i looped through it isn't
    returning it.What i mean is that want to get a Boolean value TRUE or
    FALSE when the CheckBoxlist is selected.
    Any trick for this





    *** Sent via Developersdex http://www.developersdex.com ***
     
    Patrick Olurotimi Ige, Jun 17, 2005
    #3
    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,674
    NetArchitect
    Aug 8, 2007
  2. Nevyn Twyll
    Replies:
    8
    Views:
    1,874
  3. Patrick.O.Ige
    Replies:
    5
    Views:
    19,115
    Patrick.O.Ige
    Jun 19, 2005
  4. Patrick Olurotimi Ige
    Replies:
    0
    Views:
    1,474
    Patrick Olurotimi Ige
    Jun 22, 2005
  5. Patrick.O.Ige
    Replies:
    5
    Views:
    1,099
    sana_elka
    Oct 30, 2006
Loading...

Share This Page