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

Get row from custom control

1 Answer 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Charlie
Top achievements
Rank 1
Charlie asked on 20 Nov 2015, 08:05 AM

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.-

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 25 Nov 2015, 07:31 AM
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
Tags
Grid
Asked by
Charlie
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or