日期:2014-05-17  浏览次数:20793 次

菜鸟求救。ASP页面js调用cs里面方法的问题。
js代码:
<script type="text/javascript" language="javascript">
        var del= '#<%= del.ClientID %>';
        $(document).ready(function () {
            $(del).click(function () { return Check(); });
            function Check() {
                if (typeof (Page_IsValid) == 'boolean' && !Page_IsValid) {

                    return;
                } else {
                    var count = " <%=checkCount()%>";
                    alert(count);
                }
                var checkFlg = true;
            }
        });
    </script>


cs里面的方法:
public int checkCount()
        {
            System.Web.UI.WebControls.CheckBox chkExport;
            System.Web.UI.WebControls.Label loginLabel;
            List<string> loginList = new List<string>();
            for (int i = 0; i < this.gdvData.Items.Count; i++)
            {
                chkExport = (System.Web.UI.WebControls.CheckBox)this.gdvData.Items[i].FindControl("check2");
                loginLabel = (System.Web.UI.WebControls.Label)this.gdvData.Items[i].FindControl("loginLabel");
                if (chkExport.Checked)
                {
                    string temp = loginLabel.Text;
                    loginList.Add(temp);
                }
            }
            return loginList.Count;
        }
目的就是在点del按钮的时候判断listview里面checkbox选中的个数。现在是在页面初期化的时候,第一次调用了checkcount方法。接着选中2个checkbox。点击del按钮。为什么j