2012-02-08 13 views
0

私のgridviewで私はこのコードを私のgridview行のクリックを得るために置く。GridViewクリックされた行の値

$('#grdImoveis tr').click(function() { 
     openPopup('../Financeiro/DetalheImovelProposta.aspx', 'Detalhes', 'toolbar=yes,directories=no,status=yes,menubar=yes, scrollbars=yes,resizable=yes', '850', '600', 'true'); 
    }); 

私のgridviewには5つの列があります。クリックした行の最初の列の値を取得し、クエリ文字列を渡すにはどうすればよいですか?

私はこの

$('#grdImoveis tr').click(function() { 
     // Get the value of a specific column of my clicked row. 
     //var imovel = $('# ???) 
     openPopup('../Financeiro/DetalheImovelProposta.aspx?Imovel_id=' + imovel, 'Detalhes', 'toolbar=yes,directories=no,status=yes,menubar=yes, scrollbars=yes,resizable=yes', '850', '600', 'true'); 
    }); 

マークアップのようないくつかの解決策で考える:レンダリング

<asp:GridView ID="grdImoveis" CssClass="StyleGrid" Width="100%" runat="server" AutoGenerateColumns="false" DataSourceID="dsGrid" BorderWidth="0" GridLines="None" OnRowDataBound="grdImoveis_DataBound"> 
     <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="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" /> 
     </Columns> 
    </asp:GridView> 
</div> 
    <asp:SqlDataSource ID="dsGrid" runat="server" OnSelected="ds_Selected"></asp:SqlDataSource> 

HTML:

<table class="StyleGrid" cellspacing="0" border="0" id="grdImoveis" style="border-width:0px;width:100%;border-collapse:collapse;"> 
      <tr class="thGrid" style="color:#000000;background-color:#E2DCD2;height:20px;"> 
       <th scope="col">C&#243;digo</th><th scope="col">Tipo</th><th scope="col">(L/V)</th><th scope="col">Endereco</th><th scope="col">Propostas Ativas</th> 
      </tr><tr class="EstiloDalinhaGrid" align="center"> 
       <td>373034</td><td>Apartamento 3 quartos</td><td>V</td><td> 
        Rua COUROPITA, 998541 - 
       </td><td>1</td> 
      </tr><tr class="EstiloDalinhaAlternativaGrid" align="center" style="background-color:White;"> 
       <td>372533</td><td>Apartamento 3 quartos</td><td>V</td><td> 
        Rua GIOVANI JOSÉ CHIODI, 362 - Apto 23 
       </td><td>1</td> 
      </tr><tr class="EstiloDalinhaGrid" align="center"> 
       <td>372387</td><td>Apartamento 6 quartos</td><td>V</td><td> 
        Rua GIOVANI JOSÉ CHIODI, 1625 - Fazenda 525 
       </td><td>1</td> 
      </tr><tr class="EstiloDalinhaAlternativaGrid" align="center" style="background-color:White;"> 
       <td>372383</td><td>Cobertura</td><td>V</td><td> 
        Avenida NOSSA SENHORA DO CARMO, 1623 - Loteamento 12 
       </td><td>1</td> 
      </tr><tr class="EstiloDalinhaGrid" align="center"> 
       <td>372310</td><td>Apartamento 4 quartos</td><td>V</td><td> 
        Rua MOARA, 362 - Sala 52 
       </td><td>1</td> 
      </tr><tr class="EstiloDalinhaAlternativaGrid" align="center" style="background-color:White;"> 
       <td>371853</td><td>Apartamento 3 quartos</td><td>V</td><td> 
        Rua GIOVANI JOSÉ CHIODI, 523 - Apto 362 
       </td><td>1</td> 
      </tr><tr class="EstiloDalinhaGrid" align="center"> 
       <td>370983</td><td>Apartamento 3 quartos</td><td>V</td><td> 
        Rua GIOVANI JOSÉ CHIODI, 163 - Condomínio 526 
       </td><td>1</td> 
      </tr><tr class="EstiloDalinhaAlternativaGrid" align="center" style="background-color:White;"> 
       <td>370400</td><td>Apartamento 3 quartos</td><td>V</td><td> 
        Rua teset, 35555 - 0 
       </td><td>1</td> 
      </tr><tr class="EstiloDalinhaGrid" align="center"> 
       <td>370181</td><td>Haras</td><td>V</td><td> 
        Rua A, 5266612 - Barracão 2 
       </td><td>1</td> 
      </tr><tr class="EstiloDalinhaAlternativaGrid" align="center" style="background-color:White;"> 
       <td>369833</td><td>Apartamento 4 quartos</td><td>V</td><td> 
        Rua teset, 2288 - 
       </td><td>4</td> 
      </tr><tr class="EstiloDalinhaGrid" align="center"> 
       <td>369688</td><td>Apartamento 6 quartos</td><td>V</td><td> 
        Avenida NOSSA SENHORA DO CARMO, 1665 - Vaga 2 
       </td><td>2</td> 
      </tr><tr class="EstiloDalinhaAlternativaGrid" align="center" style="background-color:White;"> 
       <td>352992</td><td>Apartamento 3 quartos</td><td>L</td><td> 
        Travessa B-5, 787878 - 
       </td><td>1</td> 
      </tr><tr class="EstiloDalinhaGrid" align="center"> 
       <td>343962</td><td>Andar/pilotis</td><td>V</td><td> 
        Avenida NOSSA SENHORA DO CARMO, 1650 - testeeee2 
       </td><td>1</td> 
      </tr> 
     </table> 
+0

私たちは、インテリジェントな答えの任意の並べ替えを与えるために、それらの行の1つのHTMLマークアップを参照してくださいする必要があります。 – Servy

+0

は私のマークアップで編集しました –

+0

これは、サーバー側のマークアップであり、HTMLマークアップではありません。これはjavascriptコードなので、最後にレンダリングされたHTMLが重要です。どのように生成するかは無関係です。 – Servy

答えて

1

javascriptのものをスキップし、代わりにそれをサーバー側を行います。 SomeTypeはあなたのデータソース内のアイテムの種類であるGridView

protected void grdImovei_RowDataBound(Object sender, GridViewRowEventArgs e) 
{ 
    if(e.Row.RowType == DataControlRowType.DataRow) 
    { 
     var url = "../Financeiro/DetalheImovelProposta.aspx?Imovel_Id=" + 
       ((SomeType)r.Row.DataItem).Imovel_id.ToString(); 

     e.Row.Attributes.Add("onclick", "openPopup('" + url + "'," + 
      @"'Detalhes', 
      'toolbar=yes,directories=no,status=yes,menubar=yes, 
      scrollbars=yes,resizable=yes', '850', '600', 'true');"); 
    } 
} 

RowDataBoundイベントに次のコードを追加します。

編集
SqlDataSourceのためにこれを試してみてください。

var url = "../Financeiro/DetalheImovelProposta.aspx?Imovel_Id=" + 
        ((DataRowView)r.Row.DataItem)["Imovel_id"].ToString(); 
+0

var urlで.Imovel_id.ToString()が見えません –

+0

あなたのデータソースは何ですか? – Magnus

+0

私はこれを試しています:var url = "../Financeiro/DetalheImovelProposta.aspx?Imovel_Id=" + e.Row.Cells [0] .ToString(); –

関連する問題