How to get the id of controls within the radgrid editform in javascript?

6 posts, 2 answers
  1. ras
    ras avatar
    12 posts
    Member since:
    Aug 2012

    Posted 21 Jan 2013 Link to this post

    hi  
       help me, how to find the controls  'rdpIntrwDate' and  'txtInterviewDateHij' within radgrid editform using javascript?
     Thanks for any suggestion



    <telerik:GridTemplateColumn HeaderText=" Interview Date " UniqueName="InterviewDate" DataField="InterviewDate"
     HeaderStyle-ForeColor="Black"  >
    <EditItemTemplate>
             <telerik:RadDatePicker ID="rdpIntrwDate" runat="server" Width="200px" DateInput-AutoCompleteType="Disabled"
                          AutoPostBack="false" SelectedDate='<%# Eval("InterviewDate")==DBNull.Value?DateTime.Today:Eval("InterviewDate") %>'
                            onkeydown="return (event.keyCode!=13);"
             CssClass="PersonalDatePicker" DateInput-DateFormat="dd/MM/yyyy" DateInput-DisplayDateFormat="dd/MM/yyyy">
               <ClientEvents OnDateSelected="GrigToHij" />
              </telerik:RadDatePicker>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="lblIntrwDate" runat="server" Text='<%# Eval("InterviewDate") %>'></asp:Label>
    </ItemTemplate>
    </telerik:GridTemplateColumn>
     
     <telerik:GridTemplateColumn HeaderText=" InterviewDateHij " UniqueName="InterviewDateHij" DataField="InterviewDateHij"
       HeaderStyle-ForeColor="Black"  >
        <EditItemTemplate>
            <telerik:RadTextBox ID="txtInterviewDateHij" runat="server"  Width="200px"
                 Height="20px" ForeColor="#0066FF">
                        <ClientEvents OnValueChanged="HijToGreg" />
             </telerik:RadTextBox>
       </EditItemTemplate>
        <ItemTemplate>
          <asp:Label ID="lblDOBHij" runat="server" Text='<%# Eval("InterviewDateHij") %>'></asp:Label>
        </ItemTemplate>
    </telerik:GridTemplateColumn>
  2. Answer
    Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 21 Jan 2013 Link to this post

    Hello,

    Please try with below code snippet.

    http://jayeshgoyani.blogspot.in/2012/07/access-radgrid-on-client.html

    Please check "Get Template Column Control" and "Access Control in Edit mode" in above link.

    Access Another control which was in same level or in row

    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Jan 2013 Link to this post

    Hi,

    Try the following code to achieve your scenario.
    C#:
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
     if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
     {
         GridEditFormItem item = (GridEditFormItem)e.Item;
         RadDatePicker pkr = (RadDatePicker)item.FindControl("rdpIntrwDate");
         RadGrid1.Controls.Add(new LiteralControl("<script type='text/javascript'>window['pkr'] = '" + pkr.ClientID + "';</script>"));
     }
    }
    JS:
    function GetValue()
    {
      var pkr= $find(window['pkr']);
    }

    Thanks,
    Shinu
  5. ras
    ras avatar
    12 posts
    Member since:
    Aug 2012

    Posted 24 Jan 2013 Link to this post

    Thanks friends...  Both worked really fine. thanks alot..
                      
  6. Rekha
    Rekha avatar
    1 posts
    Member since:
    Mar 2016

    Posted 29 Aug in reply to Jayesh Goyani Link to this post

    Hi,

    I have two radcombobox control in edititemtemplate and I have to populate ddlunit by ddlOffice selected value in Radgrid1_prerender event.

    Please look at my code and sugest me how can I do because if I do officelist.selected value.I am getting the populated combobox value instead of the selected value

     

     

     <telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" AllowAutomaticDeletes="True"
                AllowAutomaticInserts="True" OnItemDeleted="RadGrid1_ItemDeleted" OnItemInserted="RadGrid1_ItemInserted"
                OnPreRender="RadGrid1_PreRender" AllowAutomaticUpdates="True" AllowPaging="True"
                AutoGenerateColumns="False" AutoGenerateEditColumn="true" OnBatchEditCommand="RadGrid1_BatchEditCommand"  OnNeedDataSource="RadGrid1_NeedDataSource1"  OnItemDataBound="RadGrid1_ItemDataBound" GroupPanelPosition="Top">
                <MasterTableView EditMode="Batch" DataKeyNames="OfficeName,OfficeKey,Unit,OfficeUnitKey" CommandItemDisplay="Top">
                     <BatchEditingSettings EditType="Cell" />
                    <SortExpressions>
                        <telerik:GridSortExpression FieldName="AhwhKey" SortOrder="Descending" />
                    </SortExpressions>
      <Columns>
      <telerik:GridTemplateColumn HeaderText="OfficeKey" DataField="OfficeKey" UniqueName="OfficeKey" >
                                        <ItemTemplate>
                                           <%-- '<%# Eval("OfficeName")%>'--%>
                                            <asp:Label ID="Label1" runat="server"
                                              Text='<%# DataBinder.Eval(Container.DataItem, "OfficeName") %>'>
                                            </asp:Label>                                    
                                          </ItemTemplate>
                                      <EditItemTemplate>                                                                                                        
                                      <%--  <telerik:RadDropDownList  runat="server" ID="ddlOffice"   />--%>
                                          <telerik:RadComboBox runat="server" ID="ddlOffice"  onclientselectedindexchanged="OnClientSelectedIndexChanged" />
                                      </EditItemTemplate>
                                    </telerik:GridTemplateColumn>                             
                                      <telerik:GridTemplateColumn HeaderText="OfficeUnitKey" DataField="OfficeUnitKey" UniqueName="OfficeUnitKey" >
                                        <ItemTemplate>    
                                                                        
                                            <asp:Label ID="Label2" runat="server"
                                              Text='<%# DataBinder.Eval(Container.DataItem, "Unit") %>'>
                                            </asp:Label>                                    
                                          </ItemTemplate>
                                      <EditItemTemplate>                                                                                                        
                                        <telerik:RadComboBox  runat="server" ID="ddlUnit"    />
                                      </EditItemTemplate>
                                    </telerik:GridTemplateColumn>
    </Columns>
                </MasterTableView>
                <ClientSettings AllowKeyboardNavigation="true"></ClientSettings>
            </telerik:RadGrid>

    C# code:
      protected void RadGrid1_PreRender(object sender, EventArgs e)
            {
               // if ()
                {
                    XmlNode xnTboffice = default(XmlNode);
                    xnTboffice = tbws.GetTBOfficeWithofficekey();
                    DataTable dt = new DataTable();
                    dt.Columns.Add("OfficeKey", typeof(string));
                    dt.Columns.Add("OfficeName", typeof(string));
                    DataRow dr = dt.NewRow();
                    if (xnTboffice["TBResponse"].InnerXml.Contains("UNSUCCESS"))
                    {
                        dr["OfficeKey"] = xnTboffice["TBResponse"].SelectSingleNode("Message").InnerText.ToString();
                        dt.Rows.Add(dr);
                    }
                    else
                    {
                        foreach (XmlNode listItem in xnTboffice)
                        {
                            DataRow drr = dt.NewRow();
                            drr["OfficeKey"] = listItem.SelectSingleNode("OfficeKey").InnerText;
                            drr["OfficeName"] = listItem.SelectSingleNode("OfficeName").InnerText;

                            dt.Rows.Add(drr);
                        }
                    }
                    //     GridTableView masterTable = (sender as RadGrid).MasterTableView;
                    RadComboBox Officelist = (RadGrid1.MasterTableView.GetBatchColumnEditor("OfficeKey") as GridTemplateColumnEditor).ContainerControl.FindControl("ddlOffice") as RadComboBox;
                    Officelist.DataSource = dt;// binding to datatable
                    Officelist.DataTextField = "officeName";
                    Officelist.DataValueField = "OfficeKey";
                    Officelist.DataBind();



                    ////////////********Unit *****///////////////////////
                    XmlNode xnTbUnit = default(XmlNode);
                    xnTbUnit = tbintk.TBGetUnitByOffice("0");
                    DataTable dtUnit = new DataTable();

                    dtUnit.Columns.Add("Unit", typeof(string));
                    dtUnit.Columns.Add("OfficeUnitKey", typeof(string));
                    DataRow drUnit = dtUnit.NewRow();


                    if (xnTbUnit["TBResponse"].InnerXml.Contains("UNSUCCESS"))
                    {
                        drUnit["OfficeUnitKey"] = xnTbUnit["TBResponse"].SelectSingleNode("Message").InnerText.ToString();
                        dtUnit.Rows.Add(drUnit);
                    }
                    else
                    {
                        foreach (XmlNode listItem in xnTbUnit)
                        {
                            DataRow drrUnit = dtUnit.NewRow();
                            drrUnit["Unit"] = listItem.SelectSingleNode("Unit").InnerText;
                            drrUnit["OfficeUnitKey"] = listItem.SelectSingleNode("OfficeUnitKey").InnerText;

                            dtUnit.Rows.Add(drrUnit);
                        }
                    }
                    RadComboBox Unitlist = (RadGrid1.MasterTableView.GetBatchColumnEditor("OfficeUnitKey") as GridTemplateColumnEditor).ContainerControl.FindControl("ddlUnit") as RadComboBox;
                    Unitlist.DataSource = dtUnit;// binding to datatable
                    Unitlist.DataTextField = "Unit";
                    Unitlist.DataValueField = "OfficeUnitKey";
                    Unitlist.DataBind();
                }
        protected void RadGrid1_NeedDataSource1(object sender, GridNeedDataSourceEventArgs e)
            {
                RadGrid1.DataSource = this.AdoptiveServiceHistTable;
            }
       public DataTable AdoptiveServiceHistTable
            {
                get
                {
                    // DataTable res = (DataTable)this.Session["CustomersTable"];
                    DataTable dt = new DataTable();
                    try
                    {
                        // lblMessag.Text = "";
                        if (ADHIDVal.Text != "")
                        {
                            XmlNode xnTbadpthm = default(XmlNode);
                            xnTbadpthm = tbintk.TBGetAdoptHome(ADHIDVal.Text);


                            dt.Columns.Add("AhwhKey", typeof(string));
                            dt.Columns.Add("WrkrName", typeof(string));
                            dt.Columns.Add("OfficeName", typeof(string));
                            dt.Columns.Add("Unit", typeof(string));
                            dt.Columns.Add("OfficeUnitKey", typeof(string));
                            dt.Columns.Add("StartDate", typeof(string));
                            dt.Columns.Add("EndDate", typeof(string));
                            dt.Columns.Add("SupvName", typeof(string));
                            dt.Columns.Add("WrkrId", typeof(string));
                            dt.Columns.Add("AhwhAhKey", typeof(string));
                            dt.Columns.Add("OfficeKey", typeof(string));
                            dt.Columns.Add("AHWH_TEXT", typeof(string));
                            DataRow dr = dt.NewRow();


                            if (xnTbadpthm["TBResponse"].InnerXml.Contains("UNSUCCESS"))
                            {
                                dr["AhwhKey"] = xnTbadpthm["TBResponse"].SelectSingleNode("Resp").SelectSingleNode("Message").InnerText.ToString();
                                dt.Rows.Add(dr);
                            }
                            else
                            {
                                foreach (XmlNode listItem in xnTbadpthm)
                                {
                                    DataRow drr = dt.NewRow();
                                    drr["AhwhKey"] = listItem.SelectSingleNode("AhwhKey").InnerText;
                                    drr["WrkrName"] = listItem.SelectSingleNode("WrkrName").InnerText;
                                    drr["OfficeName"] = listItem.SelectSingleNode("OfficeName").InnerText;
                                    drr["Unit"] = listItem.SelectSingleNode("Unit").InnerText;
                                    drr["OfficeUnitKey"] = listItem.SelectSingleNode("OfficeUnitKey").InnerText;
                                    drr["StartDate"] = listItem.SelectSingleNode("StartDate").InnerText;
                                    drr["EndDate"] = listItem.SelectSingleNode("EndDate").InnerText;
                                    drr["SupvName"] = listItem.SelectSingleNode("SupvName").InnerText;
                                    drr["WrkrId"] = listItem.SelectSingleNode("WrkrId").InnerText;
                                    drr["AhwhAhKey"] = listItem.SelectSingleNode("AhwhAhKey").InnerText;
                                    drr["OfficeKey"] = listItem.SelectSingleNode("OfficeKey").InnerText;
                                    drr["AHWH_TEXT"] = listItem.SelectSingleNode("AHWH_TEXT").InnerText;

                                    dt.Rows.Add(drr);
                                }
                            }

                            //RadGrid1.DataSource = dt;

                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    return dt;
                }
            }
            protected void btnSearch_Click(object sender, EventArgs e)
            {
                try
                {
                    RadGrid1.Visible = true;
                    // lblMessag.Text = "";
                    XmlNode xnTbadpthm = default(XmlNode);
                    xnTbadpthm = tbintk.TBGetAdoptHome(ADHIDVal.Text);
                    DataTable dt = new DataTable();

                    dt.Columns.Add("AhwhKey", typeof(string));
                    dt.Columns.Add("WrkrName", typeof(string));
                    dt.Columns.Add("OfficeName", typeof(string));
                    dt.Columns.Add("Unit", typeof(string));
                    dt.Columns.Add("OfficeUnitKey", typeof(string));
                    dt.Columns.Add("StartDate", typeof(string));
                    dt.Columns.Add("EndDate", typeof(string));
                    dt.Columns.Add("SupvName", typeof(string));
                    dt.Columns.Add("WrkrId", typeof(string));
                    dt.Columns.Add("AhwhAhKey", typeof(string));
                    dt.Columns.Add("OfficeKey", typeof(string));
                    dt.Columns.Add("AHWH_TEXT", typeof(string));
                    DataRow dr = dt.NewRow();


                    if (xnTbadpthm["TBResponse"].InnerXml.Contains("UNSUCCESS"))
                    {
                        dr["AhwhKey"] = xnTbadpthm["TBResponse"].SelectSingleNode("Resp").SelectSingleNode("Message").InnerText.ToString();
                        dt.Rows.Add(dr);
                        //lblMessag.Text = "No Records Found";
                        RadGrid1.Visible = false;
                    }
                    else
                    {
                        foreach (XmlNode listItem in xnTbadpthm)
                        {
                            DataRow drr = dt.NewRow();
                            drr["AhwhKey"] = listItem.SelectSingleNode("AhwhKey").InnerText;
                            drr["WrkrName"] = listItem.SelectSingleNode("WrkrName").InnerText;
                            drr["OfficeName"] = listItem.SelectSingleNode("OfficeName").InnerText;
                            drr["Unit"] = listItem.SelectSingleNode("Unit").InnerText;
                            drr["OfficeUnitKey"] = listItem.SelectSingleNode("OfficeUnitKey").InnerText;
                            drr["StartDate"] = listItem.SelectSingleNode("StartDate").InnerText;
                            drr["EndDate"] = listItem.SelectSingleNode("EndDate").InnerText;
                            drr["SupvName"] = listItem.SelectSingleNode("SupvName").InnerText;
                            drr["WrkrId"] = listItem.SelectSingleNode("WrkrId").InnerText;
                            drr["AhwhAhKey"] = listItem.SelectSingleNode("AhwhAhKey").InnerText;
                            drr["OfficeKey"] = listItem.SelectSingleNode("OfficeKey").InnerText;
                            drr["AHWH_TEXT"] = listItem.SelectSingleNode("AHWH_TEXT").InnerText;

                            dt.Rows.Add(drr);
                        }
                    }

                    RadGrid1.DataSource = dt;
                    RadGrid1.DataBind();


                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

     

  7. Eyup
    Admin
    Eyup avatar
    3009 posts

    Posted 01 Sep Link to this post

    Hello Rekha,

    For achieving cascading comboboxes functionality in RadGrid InPlace edit mode, I suggest that you check the sample provided in the following post:
    http://www.telerik.com/forums/radcombobox-cascading-inside-radgrid#GxsIQqyyPkqj1Za-mNbalg


    As for accessing the combo on server-side you can use the FindControl method. For client-side, you can use the $telerik.findControl and findElement methods suggested in the following post:
    http://www.telerik.com/forums/how-to-change-and-get-value-from-a-dropdownlist-in-a-radgrid-column#jIjRiaOYhkucLZ82pztwow

    I hope this will prove helpful.

    Regards,
    Eyup
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017