gpt4 book ai didi

c# - 选中复选框时如何调用javascript函数

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:53:24 24 4
gpt4 key购买 nike

当复选框位于 gridview 中时,如何在选中该复选框时调用 Javascript 函数?

protected void AlteraStatusExpiraSeteDias_Click(object sender, EventArgs e)
{
for (int i = 0; i < 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);
}
}
}
}



<asp:GridView ID="grdImoveis2" CssClass="StyleGrid" Width="100%" runat="server" AutoGenerateColumns="false" DataSourceID="ds" BorderWidth="0" GridLines="None">
<AlternatingRowStyle BackColor="White" CssClass="EstiloDalinhaAlternativaGrid" HorizontalAlign="Center"/>
<RowStyle CssClass="EstiloDalinhaGrid" HorizontalAlign="Center" />
<HeaderStyle BackColor="#e2dcd2" CssClass="thGrid" Height="20" />
<Columns>
<asp:BoundField HeaderText="Código" DataField="Imovel_Id" />
<asp:BoundField HeaderText="Para" DataField="TransacaoSigla" />
<asp:BoundField HeaderText="Valor" DataField="ValorImovel" DataFormatString="{0:c}" HtmlEncode="false" />
<asp:TemplateField HeaderText="Endereco">
<ItemTemplate>
<%# Eval("Logradouro") %>, <%# Eval("Numero") %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Data Cadastro" DataField="DataHora" DataFormatString="{0:dd/MM/yyyy}" HtmlEncode="false"/>
<asp:BoundField HeaderText="Data Expira" DataField="DataExpira" DataFormatString="{0:dd/MM/yyyy}" HtmlEncode="false"/>
<asp:TemplateField HeaderText="Ação">
<ItemTemplate>
<asp:CheckBox ID="chkExpiraSeteDias" runat="server" onclick="alert('Foo')" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

在没有复选框的情况下,当我放置图像并将链接 href 放置到 javascript 时,它可以工作!但是有复选框,不行!

最佳答案

onclick 属性添加到复选框标记,并包含您要调用的 javascript 函数。

<asp:CheckBox ID="chkExpiraTresDias" runat="server" onclick="alert('Foo')" />

关于c# - 选中复选框时如何调用javascript函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7612218/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com