Read values from GridTemplateColumn

9 posts, 0 answers
  1. Mario
    Mario avatar
    25 posts
    Member since:
    Jan 2012

    Posted 22 Apr 2012 Link to this post

    Hello,
    I have a custom button in my grid. After clicking on the button I want the LayoutID and LayoutTypeID read from the grid TemplateColumn. I've tried the following:
    <Columns>
        <telerik:GridBoundColumn DataField="PlayerLayoutID" DataType="System.Int64"
            FilterControlAltText="Filter PlayerLayoutID column" HeaderText="PlayerLayoutID"
            ReadOnly="True" SortExpression="PlayerLayoutID"
            UniqueName="PlayerLayoutID" Visible="False">
        </telerik:GridBoundColumn>
        <telerik:GridTemplateColumn DataField="LayoutTypeID"
            FilterControlAltText="Filter LayoutTypeID column" HeaderText="Layout Type"
            UniqueName="LayoutTypeID">
            <EditItemTemplate>
                <telerik:RadComboBox ID="LayoutTypeIDRadComboBox" runat="server"
                    DataSourceID="ODSLayoutTypes"
                    DataTextField="TypeName"
                    DataValueField="TypeID"
                    onselectedindexchanged="LayoutTypeIDRadComboBox_SelectedIndexChanged"
                    AutoPostBack="True"
                    SelectedValue='<%# Bind("LayoutTypeID") %>' Culture="de-DE">
                    <Items>
                        <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem1"
                            Value="RadComboBoxItem1" />
                    </Items>
                </telerik:RadComboBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidatorLayoutType"
                    runat="server" ErrorMessage="*"
                    ControlToValidate="LayoutTypeIDRadComboBox" Display="Dynamic"></asp:RequiredFieldValidator>
                <asp:CustomValidator ID="CustomValidatorLayoutType" runat="server" ErrorMessage="*"
                    ControlToValidate="LayoutTypeIDRadComboBox" Display="Dynamic"
                    onservervalidate="CustomValidatorLayoutType_ServerValidate" ></asp:CustomValidator>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="LayoutTypeIDLabel" runat="server"
                    Text='<%# Eval("TypeName") %>'></asp:Label>
            </ItemTemplate>
        </telerik:GridTemplateColumn>
        <telerik:GridTemplateColumn DataField="LayoutID"
            FilterControlAltText="Filter column1 column" HeaderText="Layout"
            UniqueName="LayoutID">
            <EditItemTemplate>
                <telerik:RadComboBox ID="LayoutIDRadComboBox"
                    runat="server" Culture="de-DE" Width="300px" Height="300px"
                    OnClientDropDownOpened="OnClientDropDownOpenedHandler"
                    ExpandAnimation-Type="None" CollapseAnimation-Type="None"
                    <ItemTemplate>
                        <div id="div1" onclick="StopPropagation(event);">
                            <telerik:RadTreeView ID="RTVLayouts"
                                runat="server"                                                                     
                                onnodedatabound="RTVLayouts_NodeDataBound"
                                OnClientNodeClicking="nodeClicking" >
                            </telerik:RadTreeView>
                        </div>
                    </ItemTemplate>
                    <Items>
                        <telerik:RadComboBoxItem Text="" />
                    </Items>                                                   
                </telerik:RadComboBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="LayoutIDLabel" runat="server" Text='<%# Eval("LayoutName") %>'></asp:Label>
            </ItemTemplate>
        </telerik:GridTemplateColumn>
        <telerik:GridEditCommandColumn ButtonType="ImageButton"
        FilterControlAltText="Filter EditCommandColumn column"
        HeaderText="<%$ Resources:BasicSettings, Edit %>">
    </telerik:GridEditCommandColumn>
    <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete"
        ConfirmText="<%$ Resources:BasicSettings, ConfirmDelete %>"
        HeaderText="<%$ Resources:BasicSettings, Delete %>" Text="Delete"
        UniqueName="DeleteColumn">
    </telerik:GridButtonColumn>
        <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="makeObjects"
            FilterControlAltText="Filter MakeObjects column" HeaderText="Objects"
            ImageUrl="../images/symbols/settings_16.png" Text="Objects"
            UniqueName="MakeObjects">
        </telerik:GridButtonColumn>
    </Columns>
    protected void RadGridPlayerLayout_ItemCommand(object sender, GridCommandEventArgs e)
    {
        ...
        if (e.CommandName == "makeObjects")
        {
            GridDataItem item = (GridDataItem)e.Item;
            string test = item["LayoutTypeID"].Text;
             
        }
    }

    Unfortunately that did not work. How can i solve this?

    Best regards
    Reiner

  2. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 23 Apr 2012 Link to this post

    Hello Mario,

    GridDataItem item = (GridDataItem)e.Item;
              string test = (item.FindControl("LayoutTypeIDLabel") as Label).Text;


    Thanks,
    Jayesh Goyani
  3. Mario
    Mario avatar
    25 posts
    Member since:
    Jan 2012

    Posted 23 Apr 2012 Link to this post

    Thank you, Jayesh.
    Unfortunately I only get the text of the layout types name. I am using a RadComboBox in the EditItemTemplate and in the ItemTemplate i show only the TypeName, not the LayoutTypeID.
    Reiner
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Apr 2012 Link to this post

    Hello Mario,

    One option is you can add a Hiddenfield column in ItemTemplate to get the ‘LayoutTypeID’ or you can include that field into DataKeyNames and get the value using GetDataKeyValue() method.

    aspx:
    <MasterTableView DataKeyNames="LayoutID">
     <Columns>
       <telerik:GridTemplateColumn DataField="LayoutID" FilterControlAltText="Filter column1 column" HeaderText="Layout"UniqueName="LayoutID">
        <EditItemTemplate>
             .   .   .  .  .
         </EditItemTemplate>
         <ItemTemplate>
           <asp:Label ID="LayoutIDLabel" runat="server" Text='<%# Eval("LayoutName") %>'></asp:Label>
           <asp:HiddenField ID="HiddenField1" Value='<%# Eval("LayoutID") %>' runat="server" />
        </ItemTemplate>
     </telerik:GridTemplateColumn>
             .  .   .  .  .
       </Columns>
    </MasterTableView>
    C#:
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
     if (e.CommandName == "makeObjects")
     {
       GridDataItem item = (GridDataItem)e.Item;
       HiddenField hidenfield = (HiddenField)item.FindControl("HiddenField1");
       string test = hidenfield.Value;
            //  or
       string test = item.GetDataKeyValue("EmployeeID").ToString();
     }
    }

    Thanks,
    Princy.
  5. Mike Wassermann
    Mike Wassermann avatar
    2 posts
    Member since:
    Sep 2012

    Posted 19 Nov 2015 in reply to Jayesh Goyani Link to this post

    Hi can't retreaqve the value of the hiden field :

    <Columns>
                    <telerik:GridTemplateColumn HeaderText="Customer" SortExpression="LastName">
                        <ItemTemplate>
                            <strong><%#eval("LastName") %>, <%#eval("FirstName") %></strong><br />
                            <%#Eval("Address1")%><br />
                            <%#eval("City") %>, <%#eval("State") %> <%#Eval("Zip")%>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn HeaderText="Term" SortExpression="Term">
                        <ItemTemplate>
                            <asp:Label runat="server" ID="lblTerm" />
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn HeaderText="Total" DataField="Total" DataFormatString="{0:c}" SortExpression="Total" />
                    <telerik:GridBoundColumn HeaderText="VIN" DataField="Vin" SortExpression="VIN" />
                    <telerik:GridTemplateColumn HeaderText="Contract" SortExpression="ContractNum">
                        <ItemTemplate>
                            <a target="_blank" style="text-decoration: underline; color: #231F20;" href="../<%#eval("FileName") %>"><%#eval("ContractNum") %></a>
                            <input type="hidden" id="lblContract" value='<%#Eval("ContractNum") %>'></input>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>

     

     Protected Sub RadGrid1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles RadGrid1.SelectedIndexChanged
            Dim item As GridDataItem = DirectCast(RadGrid1.SelectedItems(0), GridDataItem)

            Dim test As HiddenField = DirectCast(item.FindControl("LayoutTypeIDLabel"), HiddenField)
            'Dim val = test.Value
        End Sub

     

    When I select the row I want to show the edit button and get the value in the hidden field.

    Make suggestions, since I am brand new to this.

  6. Eyup
    Admin
    Eyup avatar
    3323 posts

    Posted 24 Nov 2015 Link to this post

    Hi Mike,

    You can use a HiddenField control to achieve this requirement:
    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hiddenfield%28v=vs.90%29.aspx

    And you can access it in edit mode using the following approaches:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-controls-in-editinsert-mode

    Hope this helps. If you have different requirements or further instructions, please elaborate on your specific scenario.

    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  7. Swati
    Swati avatar
    7 posts
    Member since:
    Jan 2017

    Posted 24 Jul in reply to Princy Link to this post

    Hi,

    I am not able to find GridTemplateColumn checkbox in Item Command event.

    Getting error of casting for this line and e.item is not GridDatatitem here.

         //GridDataItem item = (GridDataItem)e.Item;   

    I have custom button in CommandItemTemplate for Save record and Commandname as "Update" . I want to get GridTemplateColumn checkbox  value in Item comamnd when Update command fires.

    How can I achieve this? Could you please help,

     

    Thank you in advance.

  8. Swati
    Swati avatar
    7 posts
    Member since:
    Jan 2017

    Posted 24 Jul in reply to Princy Link to this post

    Hi,

     I am facing error at this line of code ..

    GridDataItem item = (GridDataItem)e.Item;

     

    I want to find GridTemplateColumn Checkbox value at Item command. 

    I have custom Save button in CommandItemTemplate and command name as 'Update'

    I want to find checkbox at Item command  when 'Update' command fires 

    Could you please help? Its very urgent.

    Thank you in advance.

     

  9. Swati
    Swati avatar
    7 posts
    Member since:
    Jan 2017

    Posted 24 Jul in reply to Princy Link to this post

    hi,

    I want to find GridTemplateColumn Checkbox value at Item command. 
    I have custom Save button in CommandItemTemplate and command name as 'Update'
    I want to find checkbox at Item command  when 'Update' command fires 
    Could you please help? Its very urgent.
    Thank you in advance.

Back to Top