This is a migrated thread and some comments may be shown as answers.

Access Combo Box List items from Grid Filter Template

1 Answer 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nathan
Top achievements
Rank 2
Nathan asked on 03 Feb 2012, 08:49 PM
Hello,

I'm building up a grid programmatically. I add GridItemColumns by setting their TemplateColumn and FilterColumn to classes that inherit from ITemplate. I'm currently working on adding a multiselect dropdown filter template. I'm able to get the control to display, I just need help getting the javascript function to work correctly. The function fires on the checkbox "Onclick" event. If I can figure out how to access the combo box from within this javascript function, I'll be fine. 

My class that inherits ITemplate, adds the onclick event to the checkbox. I've added the onclick function to the main calling page. When the user clicks the checkbox, it's fired. The comboId is the combobox "ClientID". How can I pass a reference to this javascript function and access the combo box?? Please note, the checkbox inside the comboboxitem is the control firing this event and it's the "chk" parameter below:

My Main Page which contains the grid control:
function onCheckBoxClick(chk, comboId) {
    var text = "", values = "";
 
    var combo = $find(comboId);
 
    if (combo != null) {
        alert('Found ComboBox');
 
        var items = combo.get_items();
        if (items != null) {
            alert('Found Items');
 
            alert('Num Items: ' + items.length);
        } else {
            alert('NOT Found Items');
        }
 
 
    } else {
        alert('NOT Found ComboBox');
    }

This is the "InstantiateIn" method for the "ItemTemplate" section of the combo box. 
public void InstantiateIn(Control container)
{
    chkBox = new CheckBox();
    chkBox.ID = string.Format("msChk_{0}", Column);
 
    RadComboBoxItem item = (container as RadComboBoxItem);
    RadComboBox box = (item.Owner as RadComboBox);
 
    string _onClick = "";
    _onClick = string.Format("onCheckBoxClick({0}, {1})", "this", box.ClientID.ToString());
 
    chkBox.Attributes.Add("onclick", _onClick);
    chkBox.Text = item.Text;
 
    container.Controls.Add(chkBox);
}





Thanks,

1 Answer, 1 is accepted

Sort by
0
Nathan
Top achievements
Rank 2
answered on 06 Feb 2012, 04:35 PM
Please ignore, I've determined the issue. The problem was that my combo box Client ID was not contained in single quotes. The parameter was being passed to the javascript function as an object and not a string.

Correction that resolved my issue:
chkBox.Attributes.Add("onclick", "multidropdown_checked(this, '" + box.ClientID.ToString() + "'," + ColumnId + ");");

Tags
Grid
Asked by
Nathan
Top achievements
Rank 2
Answers by
Nathan
Top achievements
Rank 2
Share this question
or