0

I have a problem doing it for a week I'm working on and I would love to find a solution ... it is a web application in asp.net and c # I have a related listeview a database which I am inserting the students .. and I'd like not exceed 30 insertions ... the goal is that if I try to enter the 31th student I must be stopped displaying a warning message

I try Sev code which seems to me that here is the nearest that I put in my page load, but unfortunately its not working

if (ListView1.Items.Count>30)
{ 
   ClientScript.RegisterStartupScript(this.GetType(), 
     "myalert", 
     "alert('" + "Dsl .. étudiant !!" + "');", true);
}
4

1 回答 1

0

注意:您在问题描述中所说的只是“ ......但不幸的是它不起作用”,所以我不确定问题是什么。我假设您从未真正在if-block 内完成它。

您提到您问题中的代码位于Page_Load. 为了安全起见,我会把它放在你的数据绑定事件中ListView

ListView1_DataBound(Object sender, EventArgs e)
{
    if (ListView1.Items.Count>30)
    { 
       ClientScript.RegisterStartupScript(this.GetType(), 
         "myalert", 
         "alert('" + "Dsl .. étudiant !!" + "');", true);
    }
}

这样你就知道你ListView1.Items.Count是正确的和最新的。

于 2013-03-13T20:54:22.320 回答