Reputation: 4740
In my gridview I put this code to get the click in my gridview row.
$('#grdImoveis tr').click(function () {
openPopup('../Financeiro/DetalheImovelProposta.aspx', 'Detalhes', 'toolbar=yes,directories=no,status=yes,menubar=yes, scrollbars=yes,resizable=yes', '850', '600', 'true');
});
In my gridview I have 5 columns. How can I get the value of the first column in the clicked row and pass via querystring ?
I think in some solution like this
$('#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');
});
Markup:
<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 Rendered:
<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ó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>
Upvotes: 0
Views: 352
Reputation: 46929
Skip the javascript stuff and do it server side instead. Add the following code in the RowDataBound
event of the 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');");
}
}
Where SomeType
is the type of the items in your datasource.
Edit
For SqlDataSource
try this:
var url = "../Financeiro/DetalheImovelProposta.aspx?Imovel_Id=" +
((DataRowView)r.Row.DataItem)["Imovel_id"].ToString();
Upvotes: 1