472,145 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

How to add DataBinded CheckBoxList in Datalist

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?
Nov 19 '05 #1
2 2012
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" <Pa*********@discussions.microsoft.com> wrote in message
news:3E**********************************@microsof t.com...
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?

Nov 19 '05 #2
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 ***
Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by plz | last post: by
3 posts views Thread by Ed West | last post: by
reply views Thread by krzysiek | last post: by
4 posts views Thread by Patrick.O.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.