如何通过 jQuery 在gridview上获取特定单元格的值?
我的GridView
<asp:GridView ID="grdDetalheProposta" CssClass="StyleGrid" Width="100%" runat="server" AutoGenerateColumns="false" DataSourceID="dsGrid" BorderWidth="0" GridLines="None" OnRowDataBound="grdDetalheProposta_OnRowDataBound">
<AlternatingRowStyle BackColor="White" CssClass="EstiloDalinhaAlternativaGrid" HorizontalAlign="Center"/>
<RowStyle CssClass="EstiloDalinhaGrid" HorizontalAlign="Center" />
<HeaderStyle BackColor="#e2dcd2" ForeColor="#000" CssClass="thGrid" Height="20" />
<Columns>
<asp:BoundField HeaderText="Data" DataField="DataHora" ItemStyle-Width="1px" />
<asp:BoundField HeaderText="Valor" DataField="ValorProposta" />
<asp:BoundField HeaderText="Comentário" DataField="Comentario" />
<asp:BoundField HeaderText="Inserido Por" DataField="NomeCompleto" />
<asp:BoundField HeaderText="Credenciada Proponente" DataField="Apelido" />
<asp:BoundField HeaderText="Status" DataField="Descricao" />
<asp:TemplateField HeaderText="Ação">
<ItemTemplate>
<%= acao %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我只需要gridview的第一行,如果列'Status'具有特定值,我会在'Ação'列中添加一个特定值。但就在我的第一排。
我呈现的HTML - 我需要在第一行中获得'Andamento'的值
<div class="infoGridsemAba">
<div class='AgrupamentoPrincipal' style="background-color:#831611;padding:3px;">
Detalhes da Proposta</div>
<div class='AgrupamentoSecundario' style="background-color:#ffc274;padding:3px;">
Abaixo listando detalhes da proposta</div>
<div>
<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">Data</th><th scope="col">Valor</th><th scope="col">Comentário</th><th scope="col">Inserido Por</th><th scope="col">Credenciada Proponente</th><th scope="col">Status</th><th scope="col">Ação</th>
</tr><tr class="EstiloDalinhaGrid" align="center">
<td style="width:1px;">04/01/2012 08:58:15</td><td>88888888,77</td><td>Teste</td><td>Flávio Oliveira Santana</td><td>Central de Operações</td><td>Andamento</td><td>
</td>
</tr><tr class="EstiloDalinhaAlternativaGrid" align="center" style="background-color:White;">
<td style="width:1px;">04/01/2012 08:56:15</td><td>88888888,77</td><td>Teste</td><td>Flávio Oliveira Santana</td><td>Central de Operações</td><td>Andamento</td><td>
</td>
</tr><tr class="EstiloDalinhaGrid" align="center">
<td style="width:1px;">04/01/2012 08:56:07</td><td>88888888,77</td><td>Teste</td><td>Flávio Oliveira Santana</td><td>Central de Operações</td><td>Andamento</td><td>
</td>
</tr><tr class="EstiloDalinhaAlternativaGrid" align="center" style="background-color:White;">
<td style="width:1px;">04/01/2012 08:56:00</td><td>88888888,77</td><td>Teste</td><td>Flávio Oliveira Santana</td><td>Central de Operações</td><td>Andamento</td><td>
</td>
</tr>
</table>
</div>
</div>
答案 0 :(得分:2)
你可以尝试这个,希望完全可以使用,否则你需要稍微调整一下
//This statement should be on your aspx page where control resides
var myControlId = '<%=grdDetalheProposta.ClientID%>';
var column = $("#" + myControlId + " tr:first").next().children();
var text = $(column[5]).html(); // <= This is Zero base column index
设置值
$(column[6]).html("new value"); // <= Ação is 6th column (1st column is zeroth)
希望这适合你。
答案 1 :(得分:1)
尝试尺寸:
$("td:eq(5)", "#grdDetalheProposta tbody tr:eq(1)").html();
设置下一个单元格的值:
if ($("td:eq(5)", "#grdDetalheProposta tbody tr:eq(1)").html() === "XXX") {
$("td:eq(6)", "#grdDetalheProposta tbody tr:eq(1)").html("ZZZ");
}