2012-02-10 90 views
0

我想获得我的第一列(称为'Proposta')在相应的行中,当用户点击一个div(div在我的列' Conversa')。我怎样才能获得我的GridView中的单元格的值

我该怎么做通过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

确切欺骗http://stackoverflow.com/questions/376081/如何获取表格单元格值使用jquery – Devjosh 2012-02-10 14:14:37

+0

我不明白这个链接上的解决方案 – 2012-02-10 14:27:35

回答

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 
});