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

GridDropDownColumn in Edit Mode

3 Answers 146 Views
Grid
This is a migrated thread and some comments may be shown as answers.
diego
Top achievements
Rank 1
diego asked on 21 Jun 2012, 09:16 AM
Hello
I have a problem to solve
please, refer to this test page
1. select the item from the combo
2. in the top grid, select the 3rd row (year 2007) for edit items
3. look at the first combo (access): if the user selects PUBLIC, then the other combos (So, the question is: how can I access the combos from client side?
Here is the aspx section for the radgrid:
<telerik:RadGrid ID="gridPolicy" runat="server"
        AutoGenerateColumns="False" CellSpacing="0" DataSourceID="sqlDataPol"
        GridLines="None" OnItemDataBound="gridPolicy_OnItemDataBound" OnEditCommand="gridPolicy_OnEditCommand" Skin="Windows7" AllowFilteringByColumn="false" AllowPaging="true" PageSize="7" AllowAutomaticUpdates="true">
<MasterTableView DataKeyNames="polID" AllowFilteringByColumn="false">
    <Columns>
       <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"></telerik:GridEditCommandColumn>
        <telerik:GridBoundColumn DataField="year"
            FilterControlAltText="Filter column column" UniqueName="year" HeaderText="Year" ItemStyle-Width="20px" ReadOnly="true">
        </telerik:GridBoundColumn>
         
        <telerik:GridDropDownColumn DataField="access" UniqueName="access" ListTextField="acc" ListValueField="acc" DropDownControlType="RadComboBox" HeaderText="access" EmptyListItemText="Select" EmptyListItemValue="" DataSourceID="SqlDataSource5">
        </telerik:GridDropDownColumn>
        <telerik:GridDropDownColumn DataField="uso" UniqueName="uso" ListTextField="puse" ListValueField="puse" DropDownControlType="RadComboBox" HeaderText="Data use" EmptyListItemText="Select" EmptyListItemValue="" DataSourceID="SqlDataSource3">
        </telerik:GridDropDownColumn>
        <telerik:GridDropDownColumn DataField="pi1" UniqueName="pi1" ListTextField="prjname" ListValueField="prjname" DropDownControlType="RadComboBox" HeaderText="PI Access #1" EmptyListItemText="Select" EmptyListItemValue="" DataSourceID="SqlDataSource4">
        </telerik:GridDropDownColumn>
        <telerik:GridDropDownColumn DataField="pi2" UniqueName="pi2" ListTextField="prjname" ListValueField="prjname" DropDownControlType="RadComboBox" HeaderText="PI Access #2" EmptyListItemText="Select" EmptyListItemValue="" DataSourceID="SqlDataSource4">
        </telerik:GridDropDownColumn>
        <telerik:GridDropDownColumn DataField="pi3" UniqueName="pi3" ListTextField="prjname" ListValueField="prjname" DropDownControlType="RadComboBox" HeaderText="PI Access #3" EmptyListItemText="Select" EmptyListItemValue="" DataSourceID="SqlDataSource4">
        </telerik:GridDropDownColumn>
        <telerik:GridDropDownColumn DataField="Fluxnet" UniqueName="Fluxnet" ListTextField="FluxnetType" ListValueField="FluxnetType" DropDownControlType="RadComboBox" HeaderText="Fluxnet" EmptyListItemText="Select" EmptyListItemValue="" DataSourceID="SqlDataSource6">
        </telerik:GridDropDownColumn>
    </Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
</MasterTableView>
 
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
</HeaderContextMenu>
<ClientSettings>
    <ClientEvents OnCommand="OnCommand" />
</ClientSettings>
    </telerik:RadGrid>
Here is the codebehind section (not optimized...):
protected void gridPolicy_OnItemDataBound(object sender, GridItemEventArgs e)
       {
           string[] pis = { "pi1", "pi2", "pi3" };
           if ((e.Item is GridEditFormItem))
           {
                
               GridEditFormItem edititem = (GridEditFormItem)e.Item;
               GridEditManager editMan = edititem.EditManager;
               if (e.Item.IsInEditMode)
               {
                   if (edititem.ParentItem["Fluxnet"].Text == "Free")
                   {
                       edititem["Fluxnet"].Enabled = false;
                   }
                   else
                   {
                       GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("Fluxnet"));
                       RadComboBox combo = editor.ComboBoxControl;
                       combo.OnClientSelectedIndexChanged = "setValue";
                   }
                   if (edititem.ParentItem["access"].Text == "Public")
                   {
                       edititem["access"].Enabled = false;
                   }
                   else
                   {
                       GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("access"));
                       RadComboBox combo = editor.ComboBoxControl;
                       combo.OnClientSelectedIndexChanged = "setValue";
                   }
                   if (edititem.ParentItem["uso"].Text == "Open")
                   {
                       edititem["uso"].Enabled = false;
 
                   }
                   else
                   {
                       GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("uso"));
                       RadComboBox combo = editor.ComboBoxControl;
                       combo.OnClientSelectedIndexChanged = "setValue";
                   }
                   for (int i = 0; i < pis.Length; i++)
                   {
                       if (edititem.ParentItem[pis[i]].Text == "xxxxxxxxxxxx")
                       {
                           edititem[pis[i]].Enabled = false;
                       }
                       else
                       {
                            
                           GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor(pis[i]));
                           RadComboBox combo = editor.ComboBoxControl;
                           combo.OnClientSelectedIndexChanged = "setValue";
                       }
                        
                   }
               }
               else
               {
                    
                   for (int i = 0; i < pis.Length; i++)
                   {
 
                       if (edititem[pis[i]].Text == "xxxxxxxxxxxx")
                       {
                           edititem[pis[i]].BorderColor = System.Drawing.Color.LightBlue;
                           //Response.Write(edititem["year"].Text + " PIS " + i + " xxx<br />");
                       }
                       else
                       {
                           //Response.Write(edititem["year"].Text + " PIS " + i + " " + (edititem[pis[i]].Text.Trim().Length) + "<br />");
                            
 
                       }
                       
                   }
               }
           }
            
       }


and finally the javascript code:
<script type="text/javascript">
        var unique = new Array("access", "uso", "pi1", "pi2", "pi3", "Fluxnet");
        var oldVal = new Array("", "", "", "", "", "");
        var grid;
        var mtable;
        var index;
 
        function setValue(sender, args) {
            
            grid = $find("<%=gridPolicy.ClientID %>");
            mtable = grid.get_masterTableView();
 
            var _sender = sender.get_id();
            var value=args.get_item().get_value();
            if (_sender.indexOf("access") >= 0) {
                if (value == "Public") {
                    alert("PI a XXXX");
                     
                }
                else {
                    alert("Libera PI");
                }
            }
            else if (_sender.indexOf("uso") >= 0) {
                if (value == "Open") {
                    alert("FLUX FREE");
                }
                else {
                    alert("reset flux");
                }
            }
        }
 
        function OnCommand(sender, eventArgs) {
            index = eventArgs.get_commandArgument();
            grid = $find("<%=gridPolicy.ClientID %>");
            mtable = grid.get_masterTableView();
            var cmd = eventArgs.get_commandName();
            if (cmd == "Edit") {
                 
                var row = mtable.get_dataItems()[index];
                for (i = 2; i < mtable.get_columns().length; i++) {
                    var cell = mtable.getCellByColumnUniqueName(row, unique[i-2]);
                    var val=cell.innerHTML.toString();
                    if (val.indexOf("&") >= 0) {
                        val="";
                    }
                    oldVal[i - 2] = cell.innerHTML;
                }
 
            }
        }
    </script>

 thanks in advance
diego

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 21 Jun 2012, 10:58 AM
Hello,

Please try with Below Code snippet.
//            Please add jquery Reference then try with below code
 
            function setValue(sender, eventArgs) {
 
                var id = sender.get_id();
                id = id.replace("access", "uso");
                var usoCombo = $get(id);
               // now aceess USO column combo here
                 
            }


Thanks,
Jayesh Goyani
0
Jayesh Goyani
Top achievements
Rank 2
answered on 21 Jun 2012, 10:59 AM
0
diego
Top achievements
Rank 1
answered on 21 Jun 2012, 04:14 PM
Thanx a lot, Jayesh!
You really helped me.
Regards! 
Tags
Grid
Asked by
diego
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
diego
Top achievements
Rank 1
Share this question
or