编译器错误信息:“System.Web.UI.WebControls.ListControl.Items”是“属性”,但此处被当做“方法”来使
源代码:<scriptlanguage="C#"runat="server">voidenter_click(objectsender,System.EventArgse...
源代码:<script language ="C#" runat="server">
void enter_click(object sender,System.EventArgs e)
{
string strMessage;
strMessage="姓名:"+username.Text;
if(sex1.Checked)
{
strMessage=strMessage+"<br>性别:"+sex1.Text;
}
else if(sex2.Checked)
{
strMessage=strMessage+"<br>性别:"+sex2.Text;
}
strMessage=strMessage+"<br>婚否:"+marrage.SelectedItem.Text;
for(int i=0;i<love.Items.Count-1;i++)
{
if(love.Items(i).Checked)
{
strMessage+="<br>爱好:"+love.Items(i).Text+",";
}
}
strMessage+="<br>电话:"+phone.Text;
strMessage+="<br>地址:"+adress.Text;
strMessage+="<br>个人简介:"+person.Text;
p1.InnerHtml=strMessage;
}
void btn_Cancel(object Source,EventArgs e)
{
username.Text="";
phone.Text="";
adress.Text="";
person.Text="";
}
</script>
<html>
<body>
<h4 align="center">请填写个人信息</h4>
<form runat="server">
姓名: <asp:textBox id="username" runat="server"/><br>
性别: <asp:radioButton id =sex1 Text="男" groupname="sex" runat="server" selected/>
<asp:radioButton id =sex2 Text="女" groupname="sex" runat="server" /><br>
婚否: <asp:radioButtonList id =marrage RepeatDirection="Horizontal" runat="server" >
<asp:ListItem>末婚</asp:ListItem>
<asp:ListItem>已婚</asp:ListItem>
</asp:radioButtonList><br>
爱好:<asp:checkBoxList id ="love" runat="server">
<asp:listItem>运动</asp:listItem>
<asp:listItem>旅游</asp:listItem>
<asp:listItem>购物</asp:listItem>
<asp:listItem>音乐</asp:listItem>
</asp:checkBoxList><br>
电话: <asp:textBox id="phone" runat="server"/><br>
地址: <asp:textBox id="adress" runat="server"/><br>
个人简介:<br>
<asp:textBox id="person" rows="5" cols="60" runat="server"/><br><br><br>
<asp:button id="submit" Text ="提交" OnClick="enter_click" runat="server"/>
<asp:button id="reset" Text="取消" OnClick="btn_Cancel" runat="server"/><br>
<asp:Label id="p1" runat ="server"/>
</form>
</body>
</html>
错误提示:编译器错误信息: CS0118: “System.Web.UI.WebControls.ListControl.Items”是“属性”,但此处被当做“方法”来使用
源错误:
行 16: for(int i=0;i<love.Items.Count-1;i++)
行 17: {
行 18: if(love.Items(i).Checked)
行 19: {
行 20: strMessage+="<br>爱好:"+love.Items(i).Text+",";
}
}
第18行错误!!! 展开
void enter_click(object sender,System.EventArgs e)
{
string strMessage;
strMessage="姓名:"+username.Text;
if(sex1.Checked)
{
strMessage=strMessage+"<br>性别:"+sex1.Text;
}
else if(sex2.Checked)
{
strMessage=strMessage+"<br>性别:"+sex2.Text;
}
strMessage=strMessage+"<br>婚否:"+marrage.SelectedItem.Text;
for(int i=0;i<love.Items.Count-1;i++)
{
if(love.Items(i).Checked)
{
strMessage+="<br>爱好:"+love.Items(i).Text+",";
}
}
strMessage+="<br>电话:"+phone.Text;
strMessage+="<br>地址:"+adress.Text;
strMessage+="<br>个人简介:"+person.Text;
p1.InnerHtml=strMessage;
}
void btn_Cancel(object Source,EventArgs e)
{
username.Text="";
phone.Text="";
adress.Text="";
person.Text="";
}
</script>
<html>
<body>
<h4 align="center">请填写个人信息</h4>
<form runat="server">
姓名: <asp:textBox id="username" runat="server"/><br>
性别: <asp:radioButton id =sex1 Text="男" groupname="sex" runat="server" selected/>
<asp:radioButton id =sex2 Text="女" groupname="sex" runat="server" /><br>
婚否: <asp:radioButtonList id =marrage RepeatDirection="Horizontal" runat="server" >
<asp:ListItem>末婚</asp:ListItem>
<asp:ListItem>已婚</asp:ListItem>
</asp:radioButtonList><br>
爱好:<asp:checkBoxList id ="love" runat="server">
<asp:listItem>运动</asp:listItem>
<asp:listItem>旅游</asp:listItem>
<asp:listItem>购物</asp:listItem>
<asp:listItem>音乐</asp:listItem>
</asp:checkBoxList><br>
电话: <asp:textBox id="phone" runat="server"/><br>
地址: <asp:textBox id="adress" runat="server"/><br>
个人简介:<br>
<asp:textBox id="person" rows="5" cols="60" runat="server"/><br><br><br>
<asp:button id="submit" Text ="提交" OnClick="enter_click" runat="server"/>
<asp:button id="reset" Text="取消" OnClick="btn_Cancel" runat="server"/><br>
<asp:Label id="p1" runat ="server"/>
</form>
</body>
</html>
错误提示:编译器错误信息: CS0118: “System.Web.UI.WebControls.ListControl.Items”是“属性”,但此处被当做“方法”来使用
源错误:
行 16: for(int i=0;i<love.Items.Count-1;i++)
行 17: {
行 18: if(love.Items(i).Checked)
行 19: {
行 20: strMessage+="<br>爱好:"+love.Items(i).Text+",";
}
}
第18行错误!!! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询