Lucas_Santos
Lucas_Santos

Reputation: 4740

How can I Get the value of a cell in my gridview

I want o get the value of my first column (called 'Proposta') in the respective row, when the user click in a div (div are in my column 'Conversa').

How can I do that via Jquery ?

My ASPX

        <asp:TemplateField HeaderText="Conversa">
            <ItemTemplate>
                <div style="width:30px;">
                        <div id="lblConversa">Conversa</div>
                </div>
            </ItemTemplate>
        </asp:TemplateField>

        <asp:TemplateField HeaderText="Ação">
            <ItemTemplate>
                <%= acao %>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

My HTML rendered

    <table class="StyleGrid" cellspacing="0" border="0" id="grdDetalheProposta" style="border-width:0px;width:100%;border-collapse:collapse;">
        <tr class="thGrid" style="color:#000000;background-color:#E2DCD2;height:20px;">
            <th scope="col">Proposta</th><th scope="col">Data</th><th scope="col">Valor</th><th scope="col">Coment&#225;rio</th><th scope="col">Inserido Por</th><th scope="col">Credenciada Proponente</th><th scope="col">Status</th><th scope="col">Conversa</th><th scope="col">Ação</th>
        </tr><tr class="EstiloDalinhaGrid" align="center">
            <td>208194</td><td style="width:1px;">29/12/2011 14:32:13</td><td>11,11</td><td>Teste 1</td><td>Fl&#225;vio Oliveira Santana</td><td>Central de Opera&#231;&#245;es</td><td>Andamento</td><td>
                <div style="width:30px;">
                        <div id="lblConversa">Conversa</div>
                </div>
            </td><td>

            </td>
        </tr>
    </table>

Upvotes: 0

Views: 188

Answers (1)

ori
ori

Reputation: 7847

In the click event handler, go up from the div to the td, then back to the first child td in the same tr:

$('#grdDetalheProposta td > div').click(function() {
    var proposta = $(this).closest('td').prevAll('td:first-child').text();

    // proposta contains the value of the first td in the same row
});

Upvotes: 1

Related Questions