简体   繁体   中英

Get the value of clicked cell in Infragistics WebDataGrid using JavaScript

I have been through this since yesterday and didn't got anything except errors.

What I want is very simple, I want to get the value of a cell when I click on button in a row in Infragistics WebDataGrid using a JavaScript, here is my code:

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
 <script src="Scripts/jquery-1.10.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
    function getCellValue() {
        var grid = $find("WebDataGrid1");
        var usingActivation = grid.get_behaviors().get_selection().get_selectedRows(0).getItem(0).get_cellByColumnKey("test").get_text()
       // var usingRowSelection = grid.get_behaviors().get_activation().get_activeCell().get_row().get_cellByColumnKey("Number").get_text()
    }
</script>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<table class="nav-justified">
    <tr>
        <td>
<ig:WebDataGrid ID="WebDataGrid1" runat="server" Height="350px" Width="400px">
    <Columns>
        <ig:TemplateDataField Key="TemplateField_0">
            <ItemTemplate>
                <asp:Button ID="Button1" runat="server" OnClientClick="getCellValue()" Text="Button" />
            </ItemTemplate>
            <Header Text="TemplateField_0">
            </Header>
        </ig:TemplateDataField>
    </Columns>
    <Behaviors>
        <ig:Activation>
        </ig:Activation>
    </Behaviors>
</ig:WebDataGrid>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
        </td>
        <td>&nbsp;</td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
    </tr>
</table>

When I click on the button I found this error in the chrome debugger;

在此处输入图片说明

it looks like he didn't find the control "WebDataGrid1", any help please? I'm not that familiar with JS.

Hm, this is strange, could you try with the following as well:

var grid = ig_controls.WebDataGrid1;

OR

var grid = $find('<%= this.WebDataGrid1.ClientID %>')

grid.get_behaviors().get_selection().get_selectedRows(0).getItem(0).get_cellByColumnKey("test").get_text()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM