<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="GridView_RowsSample._Default" %>

<%@ Register Assembly="C1.Web.Wijmo.Controls.48" Namespace="C1.Web.Wijmo.Controls.C1GridView" TagPrefix="wijmo" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">

    <script>
        var grid;
        function GetGridRows() {
            grid = "#<%=C1GridView1.ClientID%>";
            var numRows = $(grid).c1gridview('dataView').totalItemCount();
            alert('rows count is ' + numRows);
        }
        function TestRowIteration() {
            var grid = "#<%=C1GridView1.ClientID%>";
            var numRows = $(grid).c1gridview('dataView').totalItemCount();

            for (var i = 0; i < numRows; i++) {
                var rowEl = $(grid).find('tr.wijmo-wijgrid-row').eq(i)[0];
                var dataItem = $(grid).c1gridview('dataView').item(i);

                // row.id equivalent → use the key field from dataItem
                var rowKey = dataItem[0]; // e.g. "1", "2", "3"

                // cell[1] DOM access
                var cell1 = $(rowEl).find('td.wijgridtd').eq(1)[0];
                cell1.setAttribute('style', 'cursor:pointer; background:yellow');

                // cell text
                var cellText = $(cell1).find('.wijmo-wijgrid-innercell').text();
                console.log('key:', rowKey, '| cell[1]:', cellText);

                // test getAttribute('trip')
                var tripJson = rowEl.getAttribute('trip');
                var trip = JSON.parse(tripJson);
                console.log('key:', rowKey, '| trip:', trip);
            }
        }
    </script>

    <button type="button" class="btn btn-primary" onclick="GetGridRows()">Get Grid Rows Count</button>
    <button type="button" class="btn btn-secondary" onclick="TestRowIteration()">Test Row Iteration</button>
    <wijmo:C1GridView ID="C1GridView1" runat="server" OnRowDataBound="C1GridView1_RowDataBound"></wijmo:C1GridView>

</asp:Content>
