替换Gridview中的Checkbox的RowCommand事件

时间:2013-04-23 07:00:02

标签: c# asp.net gridview

我在控件中有一个gridview,例如复选框和文本框。对于Checkbox,没有可用于在GridView的RowCommand Event中使用它的CommandName属性。每当复选框选中状态发生变化时,我需要在gridview外面启用一些按钮。有没有其他方法来实现这一目标?

以下是我尝试过但未启用按钮的代码段

<asp:CheckBox ID="chkFee" runat="server" AutoPostBack="true" OnCheckedChanged="chkFee_Changed" />   

           protected void chkFee_Changed(object sender, EventArgs e)
            {
                BtnCalculate.Enabled = true;
                btnSubmit.Enabled = false;                
            } 
In Javascript is called before the this Checkedchanged event,
 function Calc(obj) {

            var BtnCalculate = document.getElementById("<%= BtnCalculate.ClientID %>");
               BtnCalculate.disabled = true;
}      

1 个答案:

答案 0 :(得分:0)

这是Aspx文件..............

   <asp:CheckBox ID="chkBook" runat="server" 
    AutoPostBack="true" OnCheckedChanged="chkBook_Changed" />

这是cs文件..........

protected void chkAssignAll_CheckedChanged(object sender, EventArgs e)
            {

                GridViewRow gr = (GridViewRow) ((DataControlFieldCell) ((CheckBox) sender).Parent).Parent;
                CheckBox chk1 = (CheckBox) gr.FindControl("chkAssignSun");
                CheckBox chk2 = (CheckBox) gr.FindControl("chkAssignMon");

                chk1.Checked = ((CheckBox) sender).Checked;
                chk2.Checked = ((CheckBox)sender).Checked;                    
            }

试试这段代码.............