Is there a way to trigger a Javascript function when a checkbox within a gridview is checked?
protected void ChangeStatusSevenDays_Click(object sender, EventArgs e)
{
for (int i = 0; i < grdImoveis2.Rows.Count; i++)
{
GridViewRow RowViewSevenDaysExpire = (GridViewRow)grdImoveis2.Rows[i];
CheckBox chk = (CheckBox)grdImoveis2.Rows[i].FindControl("chkExpiraSeteDias");
if (chk != null)
{
String code;
if (chk.Checked)
{
code = (String)grdImoveis2.Rows[i].Cells[0].Text;
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Register", "ChangeStatus(code);", false);
}
}
}
}
<asp:GridView ID="grdImoveis2" CssClass="StyleGrid" Width="100%" runat="server" AutoGenerateColumns="false" DataSourceID="ds" BorderWidth="0" GridLines="None">
<AlternatingRowStyle BackColor="White" CssClass="AlternateRowStyleGrid" HorizontalAlign="Center"/>
<RowStyle CssClass="RowStyleGrid" HorizontalAlign="Center" />
<HeaderStyle BackColor="#e2dcd2" CssClass="thGrid" Height="20" />
<Columns>
<asp:BoundField HeaderText="Code" DataField="Imovel_Id" />
<asp:BoundField HeaderText="To" DataField="TransacaoSigla" />
<asp:BoundField HeaderText="Price" DataField="ValorImovel" DataFormatString="{0:c}" HtmlEncode="false" />
<asp:TemplateField HeaderText="Address">
<ItemTemplate>
<%# Eval("Logradouro") %>, <%# Eval("Numero") %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Date Added" DataField="DataHora" DataFormatString="{0:dd/MM/yyyy}" HtmlEncode="false"/>
<asp:BoundField HeaderText="Expiration Date" DataField="DataExpira" DataFormatString="{0:dd/MM/yyyy}" HtmlEncode="false"/>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:CheckBox ID="chkExpiraSeteDias" runat="server" onclick="alert('Foo')" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I've noticed that the image with a href link to Javascript works fine, but not when using checkboxes. Any suggestions?