Related Combobox on radgrid Editmode ="Popup"

6 posts, 0 answers
  1. Dang
    Dang avatar
    4 posts
    Member since:
    Dec 2010

    Posted 13 Oct 2011 Link to this post

    I have two related  radcombobox on Popup editmode : cmbBo and cmbCoquan
    ascx file
    <script type="text/javascript">
         function GetGridServerElement(serverID, tagName) {
              if (!tagName)
                  tagName = "*";

              var grid = $get("<%=RadGridCG.ClientID %>");
              var elements = grid.getElementsByTagName(tagName);
              for (var i = 0; i < elements.length; i++) {
                  var element = elements[i];
                  if (element.id.indexOf(serverID) >= 0)
                      return element;
              }
           }
           function cmbBoClientSelectedIndexChangedHandler(sender, eventArgs) {
             var cmbCoquan = GetGridServerElement("cmbCoquan");
             cmbCoquan.add_itemsRequested(cmbCoquanItemsRequested);         
             cmbCoquan.requestItems(eventArgs.get_item().get_value(), false);
         }
         function cmbCoquanItemsRequested(sender, eventArgs) {
             if (sender.get_items().get_count() > 0) {
                 // pre-select the first item
                 sender.findItemByText(sender.get_items().getItem(0).get_text()).select();
             }
             //detach the client items requested event as it not needed any more
             sender.remove_itemsRequested(cmbCoquanItemsRequested);
         }

    And in Cs file
    protected void RadGridCG_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            GridEditableItem editItem = (GridEditableItem)e.Item;
            RadComboBox cmbBo = (RadComboBox)editItem.FindControl("cmbBo");
            RadComboBox cmbCoQuan = (RadComboBox)editItem.FindControl("cmbCoQuan");
            cmbBo.OnClientSelectedIndexChanged = "cmbBoClientSelectedIndexChangedHandler";
            cmbCoQuan.ItemsRequested += new RadComboBoxItemsRequestedEventHandler(cmbCoQuan_ItemsRequested);
            //cmbBo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(cmbBo_SelectedIndexChanged);     
        }
    }
    protected void cmbCoQuan_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
    {
        GridEditableItem editItem = (sender as RadComboBox).NamingContainer as GridEditableItem;
        RadComboBox cmbCoQuan = (RadComboBox)editItem.FindControl("cmbCoQuan");
        cmbCoQuan.DataSource = LoadFilteredCoQuanManually(e.Value);
        cmbCoQuan.DataBind();
    }
    The  first cmbBo handler event cmbBoClientSelectedIndexChangedHandler successed  but i can't get the second radcombobox (cmbCoquan) , I use GetGridServerElement("cmbCoquan") method and this function not know this control as Radcombobox  (error code on cmbCoquan.requestItems(eventArgs.get_item().get_value(), false))
    My Question
    : How to get Radcombobox on RadGrid popup  use Javascript function?  Or plz show me demo code for Related combobox on  Radgrid  popup ( Editmode ="PopUp")

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 13 Oct 2011 Link to this post

    Hello Dang,

    One suggestion is to hook OnClientLoad function and save the clientID in a global variable and access the control.

    Another approach is to have a global registry (an array really) that keeps control ID's and emit script for every server control that will add an item to the global registry.  We use the fact that the server ID will always be present as a substring of the client ID, so we just loop over all registered elements and get the one that contains our server ID:

    The following code library explains the same.
    Accessing server controls in a grid template on the client.

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dang
    Dang avatar
    4 posts
    Member since:
    Dec 2010

    Posted 13 Oct 2011 Link to this post

    Thanks for  your support
     I successed get second radcombobox  use bellow function:
    var cmbCoquan;
    function OnClientLoadHandler(sender) {
              cmbCoquan = sender;
          }
    But i can't handler requestItems by  function
    function cmbBoClientSelectedIndexChangedHandler(sender, eventArgs) {
             cmbCoquan.requestItems(eventArgs.get_item().get_value(), false);
         }
    This function not call cmbCoQuan_ItemsRequested function in behind code
    protected void cmbCoQuan_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
    {
        Session["Test"] = int.Parse(Session["Test"].ToString()) + 1;
        RadComboBox cmbCoQuan = (RadComboBox)sender;
        cmbCoQuan.DataSource = LoadFilteredCoQuanManually(e.Value);
        cmbCoQuan.DataBind();
    }
    protected DataTable LoadFilteredCoQuanManually(string ID)
    {
        string SelectSQL = "";
        if (ID != "")
        {
            SelectSQL = "SELECT * FROM tblCOQUAN WHERE MABO = " + ID;
        }
        else
        {
            SelectSQL = "SELECT * FROM tblCOQUAN";
        }
        ITC.Admin.SQL SelectQuery = new ITC.Admin.SQL();
        DataTable oDataTable;
        oDataTable = SelectQuery.query_data(SelectSQL);
        return oDataTable;
    }
    Can you help me?
  5. Dang
    Dang avatar
    4 posts
    Member since:
    Dec 2010

    Posted 13 Oct 2011 Link to this post

    Please help me!
    How to call RadComboBoxItemsRequestedEventHandler  when radcombobox inside Radgrid Editmode ="Popup"?
  6. CAM
    CAM  avatar
    8 posts
    Member since:
    Apr 2008

    Posted 19 Feb 2012 Link to this post

    I also cannot produce the desired result with this code when using the popup method.
    I had to abandon.  Seems like this will also go unanswered by the experts also.  Many results on this topic.
    I wish Telerik would push out more examples with their controls on user controls...everything seems to work great when it is a flat page...rarely the option in enterprise building.
  7. Tsvetina
    Admin
    Tsvetina avatar
    1873 posts

    Posted 22 Feb 2012 Link to this post

    Hello,

    I am not sure why this code would not work in the described scenario. And what exactly happens, are there any errors on the client or the server side?

    I am attaching a modified Code library sample which implements having related combos in a UserControl opened in a PopUp edit form. You can give it a try and see if it would be useful for this or a future project.

    Regards,
    Tsvetina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017