Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I call a javascript function when Checkbox is checked
    primarykey
    data
    text
    <p>How can I call a Javascript function when a checkbox is checked when this checkbox is inside a gridview ?</p> <pre><code>protected void AlteraStatusExpiraSeteDias_Click(object sender, EventArgs e) { for (int i = 0; i &lt; grdImoveis2.Rows.Count; i++) { GridViewRow RowViewExpiraSeteDias = (GridViewRow)grdImoveis2.Rows[i]; CheckBox chk = (CheckBox)grdImoveis2.Rows[i].FindControl("chkExpiraSeteDias"); if (chk != null) { String codigo; if (chk.Checked) { codigo = (String)grdImoveis2.Rows[i].Cells[0].Text; ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Registra", "AlteraStatus(codigo);", false); } } } } &lt;asp:GridView ID="grdImoveis2" CssClass="StyleGrid" Width="100%" runat="server" AutoGenerateColumns="false" DataSourceID="ds" BorderWidth="0" GridLines="None"&gt; &lt;AlternatingRowStyle BackColor="White" CssClass="EstiloDalinhaAlternativaGrid" HorizontalAlign="Center"/&gt; &lt;RowStyle CssClass="EstiloDalinhaGrid" HorizontalAlign="Center" /&gt; &lt;HeaderStyle BackColor="#e2dcd2" CssClass="thGrid" Height="20" /&gt; &lt;Columns&gt; &lt;asp:BoundField HeaderText="Código" DataField="Imovel_Id" /&gt; &lt;asp:BoundField HeaderText="Para" DataField="TransacaoSigla" /&gt; &lt;asp:BoundField HeaderText="Valor" DataField="ValorImovel" DataFormatString="{0:c}" HtmlEncode="false" /&gt; &lt;asp:TemplateField HeaderText="Endereco"&gt; &lt;ItemTemplate&gt; &lt;%# Eval("Logradouro") %&gt;, &lt;%# Eval("Numero") %&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:BoundField HeaderText="Data Cadastro" DataField="DataHora" DataFormatString="{0:dd/MM/yyyy}" HtmlEncode="false"/&gt; &lt;asp:BoundField HeaderText="Data Expira" DataField="DataExpira" DataFormatString="{0:dd/MM/yyyy}" HtmlEncode="false"/&gt; &lt;asp:TemplateField HeaderText="Ação"&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID="chkExpiraSeteDias" runat="server" onclick="alert('Foo')" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p>Without the checkbox, when I put a image and put a link href to the javascript, it's works!, but with checkbox, no!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload