How to find control inside radgrid with out defining the field as DatakeyName

9 posts, 2 answers
  1. Dorababu
    Dorababu avatar
    95 posts
    Member since:
    May 2012

    Posted 04 Jul 2012 Link to this post

    I have designed my radgrid with gridtemplatecolumns as follows .. Sample one

    <telerik:GridTemplateColumn DataField="FirstName" AllowFiltering="true" HeaderText="First Name"
                       UniqueName="FirstName">
                       <ItemTemplate>
                           <%# Eval("FirstName")%>
                       </ItemTemplate>
                       <EditItemTemplate>
                           <telerik:RadTextBox ID="rdtxtFrstName" runat="server" Text='<%# Eval("FirstName") %>'
                               Width="150px" />
                       </EditItemTemplate>
                   </telerik:GridTemplateColumn>

    I would like to find this textbox with out adding the FirstName to Datakey in RadGrid_UpdateCommand can some one help me
  2. Answer
    Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 04 Jul 2012 Link to this post

    Hello,

    protected void dgPassanger_UpdateCommand(object sender, GridCommandEventArgs e)
            {
                GridEditableItem item = e.Item as GridEditableItem;
                RadTextBox rdtxtFrstName = item.FindControl("rdtxtFrstName") as RadTextBox;
                // Access your TextBox here
            }


    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dorababu
    Dorababu avatar
    95 posts
    Member since:
    May 2012

    Posted 05 Jul 2012 Link to this post

    Thanks Jayesh Goyani I need a small favour I would like to get the text from GridTemplatecolumn in ItemDataBund and set the selected value to dropdown 

    this is my sample 
    <telerik:GridTemplateColumn DataField="MaritalTypeID"  AllowFiltering="true" HeaderText="MaritalTypeID"
                        UniqueName="MaritalTypeID">
                        <ItemTemplate>
                            <%# Eval("MaritalTypeID")%>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadComboBox ID="rdcbGender" AutoPostBack="false" runat="server" Width="200px">
                            </telerik:RadComboBox>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>

    I need to find out the text and when binding  the drop down I would like to set the selected text to that text

    protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                GridEditableItem item = e.Item as GridEditableItem;
     
                mlocal_strStoredProcName = StoredProcNames.Gender_uspGenderGetList;
                oEmployeePersonalData.Select(out mlocal_ds, mlocal_strStoredProcName);
     
                if (!e.Item.OwnerTableView.IsItemInserted)
                {
                    RadComboBox rdcmbGender = (RadComboBox)item.FindControl("rdcbGender");
                    rdcmbGender.DataSource = mlocal_ds;
                    rdcmbGender.DataTextField = TablesAndColumns.tblGender_GenderDesc;
                    rdcmbGender.DataValueField = TablesAndColumns.tblGender_GenderTypeID;
                    rdcmbGender.DataBind();
                }
            }
        }

  5. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 05 Jul 2012 Link to this post

    Hi,

    Please try the following code snippet to give the SelectedValue in the RadComboBox.

    C#:
    if (!e.Item.OwnerTableView.IsItemInserted)
    {
        RadComboBox rdcmbGender = (RadComboBox)item.FindControl("rdcbGender");
        rdcmbGender.DataSource = mlocal_ds;
        rdcmbGender.DataTextField = TablesAndColumns.tblGender_GenderDesc;
        rdcmbGender.DataValueField = TablesAndColumns.tblGender_GenderTypeID;
        rdcmbGender.SelectedValue=(string)DataBinder.Eval(e.Item.DataItem, "MaritalTypeID").ToString(); // setting "MaritalTypeID" as selected value
        rdcmbGender.DataBind();
    }

    Hope this helps.

    Thanks,
    Princy.
  6. Dorababu
    Dorababu avatar
    95 posts
    Member since:
    May 2012

    Posted 05 Jul 2012 Link to this post

    Perfect thanks both of you
  7. João
    João avatar
    8 posts
    Member since:
    Apr 2014

    Posted 28 Apr 2014 Link to this post

    Hi, I have designed the following radgrid for using BatchEdit:

    <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SQLDSIndicadores" AutoGenerateColumns="False" GridLines="none" Culture="pt-PT" AllowAutomaticUpdates="True">
            <MasterTableView DataSourceID="SQLDSIndicadores" DataKeyNames="IDII" EditMode="Batch" CommandItemDisplay="Top">
                <BatchEditingSettings EditType="Cell" OpenEditingEvent="DblClick" />
                <GroupByExpressions>
                    <telerik:GridGroupByExpression>
                        <SelectFields>
                            <telerik:GridGroupByField FieldName="Grupo" HeaderText=" " HeaderValueSeparator=""/>
                        </SelectFields>
                        <GroupByFields>
                            <telerik:GridGroupByField FieldName="Grupo"/>
                        </GroupByFields>
                    </telerik:GridGroupByExpression>
                </GroupByExpressions>
                <CommandItemSettings ShowSaveChangesButton="true" ShowRefreshButton="False" ShowAddNewRecordButton="False" SaveChangesText="Guardar Alterações" />
                <Columns>
                    <telerik:GridBoundColumn DataField="IDII" HeaderText="IDII" Display="False"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="IDGrupo" HeaderText="IDGrupo" Display="False"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Grupo" HeaderText="Grupo" Display="False"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="IDGrupoPai" HeaderText="IDGrupoPai" Display="False"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="IDIndicador" HeaderText="ID Indicador" Display="False" HeaderStyle-Width="80%"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Indicador" HeaderText="Indicador" ReadOnly="True"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="TipoValor" HeaderText="TipoValor" Display="False" UniqueName="TipoValor"></telerik:GridBoundColumn>
                    <%--<telerik:GridBoundColumn DataField="Valor" HeaderText="Valor" UniqueName="Valor" HeaderStyle-Width="20%"></telerik:GridBoundColumn>--%>
                    <telerik:GridTemplateColumn DataField="Valor" HeaderText="Valor" UniqueName="Valor" HeaderStyle-Width="20%">
                        <ItemTemplate>
                            <asp:Label runat="server" ID="Valor" Text='<%# Bind("Valor")%>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:CheckBox ID="boolValor" runat="server" Visible="False" />
                            <telerik:RadTextBox ID="strValor" runat="server" Visible="False"></telerik:RadTextBox>
                            <telerik:RadNumericTextBox runat="server" ID="intValor" Visible="False"></telerik:RadNumericTextBox>
                            <telerik:RadNumericTextBox runat="server" ID="floatValor" Visible="False"></telerik:RadNumericTextBox>
                            <telerik:RadDatePicker ID="dateValor" runat="server" Visible="False"></telerik:RadDatePicker>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>

    What I need to do, is when I double click a cell, I want to change the visibility of EditItemTemplate controls based on the value of the column "TipoValor" and Bound the Datafield "Valor" to it. How can I do this?

    Best regards,
    João
  8. Eyup
    Admin
    Eyup avatar
    3014 posts

    Posted 01 May 2014 Link to this post

    Hello João,

    You can use the OnBatchEditOpened client-side handler provided by RadGrid:
    http://www.telerik.com/help/aspnet-ajax/grid-onbatcheditopened.html

    And use some script logic to find the required elements:
    var container = item.get_element();
    // finding RadControl:
    var control = $telerik.findControl(container, "ControlID");
    // finding element:
    var element = $telerik.findElement(container, "ElementID");

    Hope this helps.

    Regards,
    Eyup
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  9. Jawwad
    Jawwad avatar
    10 posts
    Member since:
    Dec 2014

    Posted 24 Dec 2014 Link to this post

    Hello Eyup,
         Regarding your code block in last post, from where the item is coming ? How you are setting this variable? I am unable to get the container from here.
    Also my requirement is getting the textbox in my item template. For that I guess this is the right suggestion if I get the container element.
  10. Eyup
    Admin
    Eyup avatar
    3014 posts

    Posted 29 Dec 2014 Link to this post

    Hi Jawwad,

    The item(row) is passed from event arguments:
    http://www.telerik.com/help/aspnet-ajax/grid-onbatcheditopened.html

    Hope this helps.

    Regards,
    Eyup
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017