2012-02-10 86 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 
});