如何在gridview中获取单元格的值

时间:2012-02-10 14:11:06

标签: javascript jquery

当用户点击div(div在我的专栏'Conversa'中)时,我希望在相应的行中获取我的第一列(称为'Proposta')的值。

我怎么能通过Jquery做到这一点?

我的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>

我的HTML呈现

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

1 个答案:

答案 0 :(得分:1)

在点击事件处理程序中,从div上升到td,然后返回到同一td中的第一个孩子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
});