各位好,我想在GridView 模板中添加一个CheckBox 不管我是勾上还是取消都不发生事件,我在 CS 里面这么写
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
CheckBox cb = e.Row.FindControl("CheckBox3") as CheckBox;
if (cb != null)
{
if (cb.Checked == true)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('123');", true);
}
} }
但是只有第一次才加载的时候调用,然后我有写了
protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
{ }
在这个事件中写了 可是都没有反应,我已经把 checkbox 的AutoPostBack="true" 了还是不行 不执行时间 请教一下 谁会的 ?
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
CheckBox cb = e.Row.FindControl("CheckBox3") as CheckBox;
if (cb != null)
{
if (cb.Checked == true)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('123');", true);
}
} }
但是只有第一次才加载的时候调用,然后我有写了
protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
{ }
在这个事件中写了 可是都没有反应,我已经把 checkbox 的AutoPostBack="true" 了还是不行 不执行时间 请教一下 谁会的 ?
<asp:CheckBox ID="CheckBox3" runat="server" OnCheckedChanged="CheckBox3_CheckedChanged" AutoPostBack="true" />protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
{
CheckBox cb = sender as CheckBox;
if (cb != null)
{
if (cb.Checked == true)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('123');", true);
}
} 不要动不动就手写代码!尤其是你写不明白逻辑,就尽量少写代码,尤其不要多写 RowDataBound 这种。