How to add DataBinded CheckBoxList in Datalist

G

Guest

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?
 
J

Jeremy S

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
 
P

Patrick Olurotimi Ige

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
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top