custom datagrid help! client side checkbox needed!
-
Hi All, I have a custom datagrid with two checkbox controls in it. When checkboxA is checked then if checkboxB is checked, it is unchecked and vice versa. (not like a radio button since if checkboxA is unchecked then nothing happens to checkboxB). But I would like to implement this in client side...any help would be GREATLY appreciated! schoudhr@hotmail.com
-
Hi All, I have a custom datagrid with two checkbox controls in it. When checkboxA is checked then if checkboxB is checked, it is unchecked and vice versa. (not like a radio button since if checkboxA is unchecked then nothing happens to checkboxB). But I would like to implement this in client side...any help would be GREATLY appreciated! schoudhr@hotmail.com
Well this could solve your problem in one of the OnDatabind eventhandlers you put the following code Example : here i put it in a asp:label OnDataBind eventhandler CheckBox obj = (((CheckBox)((Label)sender).Parent.Parent.FindControl("chkBlackList")));//ref to checkbox 1 CheckBox obj1 = (((CheckBox)((Label)sender).Parent.Parent.FindControl("chkDelete")));//ref to checkbox 2 //the clientside code for handling switch obj.Attributes.Add("onclick","document.getElementById('"+obj1.ClientID+"').checked = ''"); obj1.Attributes.Add("onclick","document.getElementById('"+obj.ClientID+"').checked = ''"); Wyx :cool:
-
Well this could solve your problem in one of the OnDatabind eventhandlers you put the following code Example : here i put it in a asp:label OnDataBind eventhandler CheckBox obj = (((CheckBox)((Label)sender).Parent.Parent.FindControl("chkBlackList")));//ref to checkbox 1 CheckBox obj1 = (((CheckBox)((Label)sender).Parent.Parent.FindControl("chkDelete")));//ref to checkbox 2 //the clientside code for handling switch obj.Attributes.Add("onclick","document.getElementById('"+obj1.ClientID+"').checked = ''"); obj1.Attributes.Add("onclick","document.getElementById('"+obj.ClientID+"').checked = ''"); Wyx :cool:
Hi, I really appreciate your help...I'm new at this so please bear with me... on this line: obj.Attributes.Add("onclick","document.getElementById('"+obj1.ClientID+"').checked = ''"); am I supposed to replace the empty string with true or false like this: obj.Attributes.Add("onclick","document.getElementById('"+obj1.ClientID+"').checked = true"); also, on this line: CheckBox obj = (((CheckBox)((Label)sender).Parent.Parent.FindControl("chkBlackList")));
-
Well this could solve your problem in one of the OnDatabind eventhandlers you put the following code Example : here i put it in a asp:label OnDataBind eventhandler CheckBox obj = (((CheckBox)((Label)sender).Parent.Parent.FindControl("chkBlackList")));//ref to checkbox 1 CheckBox obj1 = (((CheckBox)((Label)sender).Parent.Parent.FindControl("chkDelete")));//ref to checkbox 2 //the clientside code for handling switch obj.Attributes.Add("onclick","document.getElementById('"+obj1.ClientID+"').checked = ''"); obj1.Attributes.Add("onclick","document.getElementById('"+obj.ClientID+"').checked = ''"); Wyx :cool:
also, when i try to access the object using obj.Attributes.Add("onclick","document.getElementById('"+obj1.ClientID+"').checked = ''"); obj1.Attributes.Add("onclick","document.getElementById('"+obj.ClientID+"').checked = ''"); I get an 'document.getElementById' is null or not an object error any ideas?
-
also, when i try to access the object using obj.Attributes.Add("onclick","document.getElementById('"+obj1.ClientID+"').checked = ''"); obj1.Attributes.Add("onclick","document.getElementById('"+obj.ClientID+"').checked = ''"); I get an 'document.getElementById' is null or not an object error any ideas?
Q1 Well you dont have to replace empty with true because all that this do is to remove checkmark on checkbox the checkmark is set clientside automatically this the onclick event only handles removeal af the checkbox Q2 if you get null it could be that the Eventhandler in which you do the attributes add is fired to early so the ClientId is has not been provided yet if eg. you do it in the item created eventhandler of the datagrid the ClientId is the same as the Id and will not work you can see if that is the problem by looking at the sóurcecode of the rendered HTML the id generated in the onclick event you have added should be something like MyDatagrid_checkbox1 and so forth with the number increasing for each checkbox in the grid Wyx :cool:
-
Q1 Well you dont have to replace empty with true because all that this do is to remove checkmark on checkbox the checkmark is set clientside automatically this the onclick event only handles removeal af the checkbox Q2 if you get null it could be that the Eventhandler in which you do the attributes add is fired to early so the ClientId is has not been provided yet if eg. you do it in the item created eventhandler of the datagrid the ClientId is the same as the Id and will not work you can see if that is the problem by looking at the sóurcecode of the rendered HTML the id generated in the onclick event you have added should be something like MyDatagrid_checkbox1 and so forth with the number increasing for each checkbox in the grid Wyx :cool:
Hi Thanks alot for your help.. I really appreciate it. Just one last thing... The entire datagrid is coded in C# with no HTML so there is no rendered HTML code... so how can I access the checkboxes? In this line, CheckBox obj = (((CheckBox)((Label)sender).Parent.Parent.FindControl("chkBlackList"))); What would I use for "chkBlackList"? I have no HTML...
-
Hi Thanks alot for your help.. I really appreciate it. Just one last thing... The entire datagrid is coded in C# with no HTML so there is no rendered HTML code... so how can I access the checkboxes? In this line, CheckBox obj = (((CheckBox)((Label)sender).Parent.Parent.FindControl("chkBlackList"))); What would I use for "chkBlackList"? I have no HTML...
Well i know that you did nopt write any html But every asp.net control is rendered as plain html when shown in the browser. Label is rendered as spans, datagrids as tables and etc, etc But if you are working in windows forms, this is actually the wron forum it shouild be posted in C# area.