2012-03-02 4 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> 

Drawing (пример):

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

Я хочу, чтобы получить с помощью JQuery значение последнего столбца (Cons), но пользователь не может видеть этот столбец. Как я могу скрыть и получить значение этого столбца в каждой строке?

ответ

1

Самый простой способ:

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

Чтобы получить значение на клик или другое событие, вы можете использовать:

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

Проверьте, что такое идентификатор вашей таблицы. Предполагая, что это grdImoveis, то:

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

Но, с этим кодом, только последние данные в моей сетке будет скрываться. Я хочу скрыть весь этот столбец и получить значение каждой строки –

1

Предполагая, что ваша колонка Cons всегда является последним из вашей таблицы, это должно сделать это:

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/

Смежные вопросы