2012-03-02 87 views
0

如何在我的表中隱藏特定的TD?獲得TD標籤的具體價值

呈現的頁面:

<table> 
    <tr> 
    <th>Codigo</th> 
    <th>Tipo</th> 
    <th>(L/V)</th> 
    <th>Endereco</th> 
    <th>Propostas Ativas</th> 
    <th>Cons</th> 
    </tr> 
    <tr> 
    <td>373054</td> 
    <td>Apartamento</td> 
    <td>V</td> 
    <td>Rua DO FURQUIM</td> 
    <td>1</td> 
    <td>0</td> 
    </tr> 
</table> 

ASP頁:

<asp:GridView ID="grdImoveis" Width="100%" runat="server" AutoGenerateColumns="false" DataSourceID="dsGrid" OnRowDataBound="grdImoveis_DataBound"> 
    <Columns> 
     <asp:BoundField HeaderText="Código" DataField="Imovel_Id" />    
     <asp:BoundField HeaderText="Tipo" DataField="TipoDsc1" /> 
     <asp:BoundField HeaderText="(L/V)" DataField="TransacaoSigla" /> 
     <asp:TemplateField HeaderText="Endereco"> 
      <ItemTemplate> 
       <%# Eval("Descricao") %> <%# Eval("Logradouro") %>, <%# Eval("Numero") %> - <%# Eval("Expr1") %> <%# Eval("Complemento") %> 
      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:BoundField HeaderText="Propostas Ativas" DataField="NumeroProposta" /> 
     <asp:BoundField HeaderText="Cons" DataField="FoundInSanNegocio" /> 
    </Columns> 
</asp:GridView> 

圖(例):

Código  Tipo   (L/V)  Endereço   Propostas Ativas  Cons 
373054  Apartamento V   Rua Do Furquim 1      0 

我想通過JQuery拿到最後一列的值(缺點),但用戶無法看到此列。我怎樣才能在每一行中隱藏和獲取這列的價值?

回答

1

最簡單方法是:

$(document).ready(function(){ 
    $('#<%=grdImoveis.ClientID %>').find('tr').each(function(){ 
     $(this).find('td:last').hide(); 
    }); 
    }); 

要獲得點擊或其他一些事件的價值,你可以使用:

var value= $(this).find('td:last').text(); 
0

檢查你的表的ID是什麼。假設它的grdImoveis,則:

// Hide last column and and get its value (text) 
var comp = $("#grdImoveis TD:last").hide().text(); 
+0

但是,與此代碼,剛剛過去的數據在我的網格將被隱藏起來。我想隱藏所有這一列,並獲得每一行的值 – 2012-03-02 14:52:01

1

假設你的缺點列一直是你的表的最後一個,這應該這樣做:

var myVar = ''; 
var myArray = new Array(); 

$('tr').each(function() { 
    //this fetches the text content of the last cell of the current row: 
    myVar = $(this).children("td:last").text(); 
    //this puts that value at the end of the myArray array 
    myArray.push(myVar); 
    //this hides that td 
    $(this).children("td:last").hide(); 
}); 

我做了一個的jsfiddle它,似乎工作。 http://jsfiddle.net/qnvHM/