After struggling with the control for a while I was able to create the control dynamically. this is the functionality i am using:
The class :
class ItemTemplate : ITemplate
{
public void InstantiateIn(Control container)
{
CheckBox checkBox = new CheckBox();
checkBox.ID = "CheckBox1";
//checkBox.DataBinding += new EventHandler(checkBox_DataBinding);
container.Controls.Add(checkBox);
RadioButton radioButton = new RadioButton();
radioButton.ID = "RadioButton1";
//radioButton.DataBinding += new EventHandler(radioButton_DataBinding);
container.Controls.Add(radioButton);
LiteralControl lc = new LiteralControl();
lc.DataBinding += new EventHandler(label_DataBinding);
container.Controls.Add(lc);
}
private void checkBox_DataBinding(object sender, EventArgs e)
{
CheckBox target = (CheckBox)sender;
RadListBoxItem item = (RadListBoxItem)target.BindingContainer;
}
private void radioButton_DataBinding(object sender, EventArgs e)
{
RadioButton target = (RadioButton)sender;
RadListBoxItem item = (RadListBoxItem)target.BindingContainer;
}
private void label_DataBinding(object sender, EventArgs e)
{
LiteralControl target = (LiteralControl)sender;
RadListBoxItem item = (RadListBoxItem)target.BindingContainer;
target.Text = (string)DataBinder.Eval(item, "Text");
}
}
I have the desired checkboxes and radio buttons. However, I want the user to be able to select only one radiobutton at any given time. The current functionality allows the user to check multiple radio buttons. I had a similar functionality with a combo box where I call the 'SetUniqueRadioButton' onclick event and it does the required. I used the same function here but it did not give me the desired results.
Is it because now the control is being created dynamically so the ID changes? Could you help me with the solution here.
Posted below is the js code:
Please help.