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

attaching onblur and onfocus to radcombobox griddropdowncolumn for radgrid in edit mode

2 Answers 176 Views
Grid
This is a migrated thread and some comments may be shown as answers.
EJ
Top achievements
Rank 1
EJ asked on 15 Jun 2010, 12:38 PM
I have my grid in edit mode for all rows all the time and I need to place onblur and onfocus javascript client side events to each individual radcombobox that is generated in edit mode in this grid but I don't seem to be able to figure out how to attach these events to the right control

it looks like from the markup that the
dataItem["attendancekind"].Controls[0].ClientID + "_Input'
is the clientid of the combobox

i saw this article that talks about how to attach onblur event to a combobox but it seems to refer to an older non-ajax version - I'm using the latest 2010 telerik ajax version
'

aspx

<telerik:RadGrid ID="MyRadGrid" runat="server" AutoGenerateColumns="False" 
                        Width="300px" DataSourceID="MyObjectDataSource" AllowAutomaticDeletes="True" 
                        AllowAutomaticInserts="True" AllowAutomaticUpdates="True" GridLines="None" AllowMultiRowEdit="True" 
                        OnPreRender="MyRadGrid_PreRender"
                        <ClientSettings EnablePostBackOnRowClick="True"
                            <Selecting AllowRowSelect="True" /> 
                        </ClientSettings> 
                        <MasterTableView DataKeyNames="myid" DataSourceID="MyObjectDataSource" 
                            EditMode="InPlace" InsertItemPageIndexAction="ShowItemOnCurrentPage"
                            <Columns> 
                                <telerik:GridBoundColumn DataField="myid" Display="False" UniqueName="myid"
                                </telerik:GridBoundColumn> 
                                <telerik:GridDropDownColumn DataField="anotherid" DataSourceID="PersonObjectDataSource" 
                                    HeaderText="Name" ListTextField="name" ListValueField="anotherid" DataType="System.Guid" 
                                    UniqueName="anotherid"
                                </telerik:GridDropDownColumn> 
                                <telerik:GridDropDownColumn DataField="attendancekind" DataSourceID="MyKindObjectDataSource" 
                                    HeaderText="" ListTextField="description" ListValueField="attendancekind" 
                                    DataType="System.Guid" UniqueName="attendancekind"
                                </telerik:GridDropDownColumn> 
                                <telerik:GridClientSelectColumn Display="False" UniqueName="column"
                                </telerik:GridClientSelectColumn> 
                            </Columns> 
                        </MasterTableView> 
                    </telerik:RadGrid> 


code behind

protected void MyRadGrid_PreRender(object sender, EventArgs e) 
        { 
            // put all items in edit mode by default 
            for (int i = 0; i < MyRadGrid.PageSize; i++) 
            { 
                MyRadGrid.EditIndexes.Add(i); 
            } 
 
            MyRadGrid.Rebind(); 
 
            //subtotal 
            foreach (GridDataItem dataItem in MyRadGrid.MasterTableView.Items) 
            { 
                (dataItem["attendancekind"].Controls[0] as RadComboBox).Attributes.Add( 
                    "onblur", "update(''" + dataItem["attendancekind"].Controls[0].ClientID + "_Input');"); 
 
(dataItem["attendancekind"].Controls[0] as RadComboBox).Attributes.Add( 
                    "onfocus", "getInitialValue('" + dataItem["attendancekind"].Controls[0].ClientID + "_Input');"); 
 

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 15 Jun 2010, 02:28 PM
Hello,

You can attach OnClientBlur and OnClientFocus event to RadComboBox in ItemCreated event.

C#:
 
 protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem edititem=(GridEditableItem)e.Item; 
            RadComboBox combo = (RadComboBox)edititem["attendancekind"].Controls[0]; 
            combo.OnClientBlur = "update"
            combo.OnClientFocus = "getInitialValue"
        } 
     } 
 

Java Script:
<script type="text/javascript"
    function update(sender, eventArgs) 
     { 
          // your code 
     } 
    function getInitialValue(sender, eventArgs)  
     { 
          var combo = sender;    //access the ComboBox 
          //your code 
     } 
</script> 

Thanks,
Princy.


0
EJ
Top achievements
Rank 1
answered on 15 Jun 2010, 09:50 PM
thanks!
Tags
Grid
Asked by
EJ
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
EJ
Top achievements
Rank 1
Share this question
or