Add Attribute to CheckBoxList ListItem at runtime?

C

CK

Hi All,
I have an asp:CheckBoxList. it is databound to a datatable at runtime;

private void chklstStatuses_DataBinding(object sender, EventArgs e)

{

chklstStatuses.DataSource = BillingInvoiceUtil.GetStatuses();

chklstStatuses.DataTextField = "StatusName";

chklstStatuses.DataValueField = "InvoiceStatusID";

}



I need to add an attribute to each list item,
"onClick=javascript:setFilter(this);"

I can not get it to work. I tried two different methods in two different
events, in chklstStatuses_DataBinding & in chklstStatuses_PreRender.

I try it like this

for(int x = 0; x != chklstStatuses.Items.Count; x++)

{

ListItem li = chklstStatuses.Items[x];

li.Attributes.Add("onClick","javascript:setFilter(this);");

}

doesn't work and I also tried
IEnumerator chklstEnumerator;

ListItem li;

chklstEnumerator = chklstStatuses.Items.GetEnumerator();

while(chklstEnumerator.MoveNext())

{

li = (ListItem)chklstEnumerator.Current;

li.Attributes.Add("onClick","javascript:setFilter(this);");

}

Neither one of these methods renders the attribute. I a compile fine and i
get no runtime or javascript errors in either case. I view the page source
and the attribute just doesn't seem to render.
Can anyone help?

Thanks,
~CK
 

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,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top