Get row from custom control

2 posts, 0 answers
  1. Charlie
    Charlie avatar
    1 posts
    Member since:
    Nov 2015

    Posted 20 Nov 2015 Link to this post

    Hello everybody

     

    I'm working currently on a application that uses telerik for all controls except some special type called "bowserfield", is like an inputbox with autocomplete. I need to use this control mandatory.

     

     My problem starts when I try to use this control inside a itemtemplate and want to get the row in this customcontrol onclick event. I have the row number in RANK1 control, could I use this inputbox to get the row number? I could use ONCLICK in server side, but I dont know how to get the radgrid sender reference. ALso notice that I dont have the row selected when the event is launched from this control.

     

     

    My case:

     

     <telerik:GridTemplateColumn HeaderText="BB" HeaderStyle-Width="15%" UniqueName="cv" > 
                                      <ItemTemplate> 
                                      <asp:hiddenfield  runat="server" id="KEY1" Value='<%# Bind("ID") %>'  ></asp:hiddenfield> 
                                      <asp:hiddenfield  runat="server" id="RANK1" Value='<%# Bind("rank") %>'  ></asp:hiddenfield> 
                                      <et:bowsefield runat="server" id="DocID" bowsername="document" OnChange="Save($(this),'1')"/>
                   </ItemTemplate> 
    </telerik:GridTemplateColumn> 

     

     

     

     <script type="text/javascript">

     function Save(sender, args)
        {
            if (sender != null) {
                var grid = $find('<%= RadGrid1.ClientID %>'); 
                var MasterTable = grid.get_masterTableView();
                var tableEl = MasterTable.get_element();

                var DocX
                var idX

                if (args == '1')
                {
                   
                    var textBox = sender[0].$telerik.findElement(tableEl, "DocID"); ----> GIVES ME ALWAYS ROW 1 :(
                }
                ...
            }
        }

    </script>

     

    I think that a solution could be use this control only in edit mode, but is possible to do without it? Thanks a lot.-

     

     

     

     

     

  2. Eyup
    Admin
    Eyup avatar
    3819 posts

    Posted 25 Nov 2015 Link to this post

    Hello Charlie,

    You can achieve this requirement both on server and client-side. In the latter case, you can use something similar to this:
    <ItemTemplate>
        <asp:CheckBox ID="CheckBox1" runat="server"
            onchange='<%# string.Format("checkBoxChange(this,\"1\",\"{0}\",{1});",
        Container.OwnerTableView.ClientID, Container.ItemIndex) %>' />
    </ItemTemplate>
    JavaScript:
    function checkBoxChange(checkBox, arg, tableViewID, itemIndex) {
        var tableView = $find(tableViewID);
        var item = tableView.get_dataItems()[itemIndex];
        alert(item.get_cell("Freight").innerText);
        // execute one of the approaches in the provided article section
    }

    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-cells-and-values-in-client-side-code

    Hope this helps. Please give it a try and let me know if it works for you.

    As a side note, please keep in mind that creating custom controls is beyond our support scope even if they are inherited directly from Telerik UI controls. If you happen to come across the need to implement something like this, you can use UserControls.

    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
Back to Top