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

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

8 Answers 639 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dorababu
Top achievements
Rank 1
Dorababu asked on 04 Jul 2012, 04:20 PM
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

8 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 04 Jul 2012, 04:45 PM
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
0
Dorababu
Top achievements
Rank 1
answered on 05 Jul 2012, 08:41 AM
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();
            }
        }
    }

0
Accepted
Princy
Top achievements
Rank 2
answered on 05 Jul 2012, 09:13 AM
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.
0
Dorababu
Top achievements
Rank 1
answered on 05 Jul 2012, 09:43 AM
Perfect thanks both of you
0
João
Top achievements
Rank 1
answered on 28 Apr 2014, 02:30 PM
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
0
Eyup
Telerik team
answered on 01 May 2014, 08:50 AM
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.

 
0
Jawwad
Top achievements
Rank 1
answered on 24 Dec 2014, 12:46 PM
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.
0
Eyup
Telerik team
answered on 29 Dec 2014, 09:47 AM
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.

 
Tags
Grid
Asked by
Dorababu
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Dorababu
Top achievements
Rank 1
Princy
Top achievements
Rank 2
João
Top achievements
Rank 1
Eyup
Telerik team
Jawwad
Top achievements
Rank 1
Share this question
or