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

Related Combobox on radgrid Editmode ="Popup"

5 Answers 147 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dang
Top achievements
Rank 1
Dang asked on 13 Oct 2011, 08:24 AM
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")

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 13 Oct 2011, 08:48 AM
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.
0
Dang
Top achievements
Rank 1
answered on 13 Oct 2011, 10:09 AM
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?
0
Dang
Top achievements
Rank 1
answered on 14 Oct 2011, 03:13 AM
Please help me!
How to call RadComboBoxItemsRequestedEventHandler  when radcombobox inside Radgrid Editmode ="Popup"?
0
CAM
Top achievements
Rank 1
answered on 20 Feb 2012, 04:36 AM
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.
0
Tsvetina
Telerik team
answered on 22 Feb 2012, 03:47 PM
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.
Tags
Grid
Asked by
Dang
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Dang
Top achievements
Rank 1
CAM
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or