title: How to add OnClientClick to DDL in c# codebehind
body: <p>I am dynamically creating a table that contains two drop down lists. I want to fire an OnClientClick event to execute some JavaScript when either DDL is selected, but don't see a way to add an OnClientClick to a DDL. Here is the code as it currently sits. I tried adding the OnClientClick to the Item, but it isn't working.</p>
  
  <pre><code>HtmlTableCell tableCell = new HtmlTableCell();
  tableCell.Attributes.Add("class", cssPageGroups);
  
  DropDownList ddlPageGroups = new DropDownList();
  ddlPageGroups.Attributes.Add("class", cssPageGroupsDDL);
  ddlPageGroups.ID = "ddlPageGroups";
  ddlPageGroups.AutoPostBack = true;
  ddlPageGroups.SelectedIndexChanged += new EventHandler(pageGroupChange);
  
  for (int pg = 1; pg &lt;= maxPageGroups; pg++)
    {
      int groupFirstPageNumber = (int)(1 + (maxVisiblePageNumbers * (pg - 1)));
      int groupLastPageNumber = groupFirstPageNumber + (maxVisiblePageNumbers - 1);
      if (totalPages &lt; groupLastPageNumber)
      {
       groupLastPageNumber = totalPages;
      }
      string group = String.Format("{0} ... {1}", groupFirstPageNumber.ToString(), groupLastPageNumber.ToString());
      ListItem groupItem = new ListItem(group, ((groupFirstPageNumber - 1) * pageSize).ToString());
      if (pageGroup == pg)
      {
        groupItem.Selected = true;
      }
      groupItem.Attributes.Add("OnClientClick", "javascript:showSearching();");
      ddlPageGroups.Items.Add(groupItem);
  }
  </code></pre>