Friday, February 6, 2009

Fire Item Command on DataList when CheckBox is Clicked

Hi
Today i am wondering to get a problem, when i fired a checkbox (postback enabled) will not wire up the item command on data list. and when i replace checkbox with button it works. 0) then i got a wise solution that keep a button in datalist and explicty genrate its click event when check box is clicked. for this i put code in item databound event of datalist.


// Find controls : -
CheckBox chk1 = (CheckBox)(e.Item.FindControl("chk1"));
Button Button1 = (Button)(e.Item.FindControl("Button1"));
// Add javasCript on onClick event to check box which call click evetnt of button. and after it
// Item command will fire

chk1.Attributes.Add("OnClick",
"javascript:document.getElementById('" + Button1.ClientID + "').click()");

Thansk
HelpOnDesk Team

2 comments:

Anonymous said...

Thank you for your code.This really works.

Anonymous said...

Thank you for your code.This really works.