This is a migrated thread and some comments may be shown as answers.
Find Row Value of radgrid on client side
2 Answers 106 Views
This is a migrated thread and some comments may be shown as answers.
Tolga
Top achievements
Rank 1
Tolga asked on 28 Jan 2015, 03:01 PM
Hello,I have a radgrid with some bound columns. In one of the bound columns, it has ImageButton. All I want is Javascript function when I click the button i want to get value of this row of the button.

It means when I click ImageButton 'CizelgeAc' I want to get EKD_ID of this selected row. my javascript function is 'cizelgeAc1(this,event)


<telerik:GridTemplateColumn HeaderText="Kurs Prog. Çiz." UniqueName="KursProgCiz" DataField="EKD_ID" SortExpression="EKD_ID" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" AllowFiltering="false">
                                                <ItemTemplate>
                                                    <asp:ImageButton ID="CizelgeAc" CommandName="ES" runat="server" CausesValidation="false" OnClientClick="cizelgeAc1(this,event)"
                                                        Visible='<%# (((((string)Eval("EGT_TIPI").ToString() == "V"))) ? true : false) %>'
                                                        ImageUrl="~/Images/AddRecord.gif" />
                                                    <asp:Label runat="server" Visible='<%# (((((string)Eval("EGT_TIPI").ToString() == "A"))) ? true : false) %>' Text="-"></asp:Label>
                                                    <%--                                                    <asp:Image ID="imageKursProgCiz" runat="server" ImageUrl="~/Images/Cancel.gif" Visible='<%# (((((string)Eval("EGT_TIPI").ToString() == "A"))) ? true : false) %>' />                                                  --%>
                                                </ItemTemplate>
                                            </telerik:GridTemplateColumn>

Javascript Function : 

function cizelgeAc1(button, args) {
                var row = Telerik.Web.UI.Grid.GetFirstParentByTagName(button, "tr");
                //guarantee to get to the table row
                while (!(row.id && row.id.indexOf("__") > -1)) {
                    row = Telerik.Web.UI.Grid.GetFirstParentByTagName(button, "tr");
                }
 
                //get index
                var index = row.id.split("__")[1];
 
                //get all table data items
                var tableId = row.id.split("__")[0];
                var tableView = $find(tableId);
                tableView.get_dataItems();
                //find the data item related to the row id
                var dataItem = $find(row.id);
                var grid = button;
                var MasterTable = EgitimTalepleriRadGrid.get_masterTableView();
                 var cell= grid.get_masterTableView().get_dataItems()[0].get_cell("EKD_ID").innerHTML;
 
            }

I got the row index but I couldn't reach value of 'EKD_ID' in this way.

2 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 02 Feb 2015, 11:29 AM
Hello Tolga,

You can use following approach to achieve the requested functionality:
<MasterTableView ... ClientDataKeyNames="OrderID">
ImageButton definition:
<asp:ImageButton ... OnClientClick='<%# "cizelgeAc1(this,event,"+Container.ItemIndex+",\""+
                            Container.OwnerTableView.ClientID+"\"); return false;" %>'/>
JavaScript:
function cizelgeAc1(button, event, index, tableViewID) {
    var tableView = $find(tableViewID);
    var item = $find(tableViewID).get_dataItems()[index];
    var value = item.getDataKeyValue("OrderID");
    alert(value);
}

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

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
Ilaya
Top achievements
Rank 1
answered on 13 Dec 2018, 06:44 AM

Hi Sir,

Its is Working Perfectly . thank you so much.

Regards

Ilaya

Tags
Grid
Asked by
Tolga
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Ilaya
Top achievements
Rank 1
Share this question
or