我是新学习ASP的,对于其中一些控件的使用觉得很疑惑,书上讲解并不是很清楚,所以一下的程序可能有点错误:
怎样写才能使得dropdownlist里的第一项“等于"在第一次打开页面时可以响应呢,目前是选择后没有反应的..
谢谢大家的帮忙,小女子谢过......~~O(∩_∩)O<script language ="C#" runat ="server" > void Page_Load(object src, EventArgs e)
{
//设定比较的操作符 compvalid.Operator = (ValidationCompareOperator)opera.SelectedIndex;
} public void selected(object sender, EventArgs e)
{ Page.Validate();
if (Page.IsValid)
{
label1.Text = "已通过验证";
}
else
label1.Text = "未通过验证";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>CompareValidator控件</title>
</head>
<body>
<form id="form1" runat="server">
<table >
<tr>
<td colspan ="2" align ="center" >Compare验证控件演示</td>
</tr>
<tr>
<td>需要验证的数字:</td>
<td><asp:TextBox ID="number" runat ="server" ></asp:TextBox>
</td>
</tr>
<tr>
<td>与之比较的数字:</td>
<td><asp:TextBox ID="comparenum" runat ="server" ></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:DropDownList ID="opera" AutoPostBack ="true" OnSelectedIndexChanged ="selected" runat ="server" >
<asp:ListItem Value ="Equal" >等于</asp:ListItem>
<asp:ListItem Value ="NotEqual">不等于</asp:ListItem>
<asp:ListItem Value ="GraterThan" >大于</asp:ListItem>
<asp:ListItem Value ="GreaterThanEqual" >大于或等于</asp:ListItem>
<asp:ListItem Value ="LessThan" >小于</asp:ListItem>
<asp:ListItem Value ="LessThanEqual" >小于或等于</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
<hr />
<asp:CompareValidator ID="compvalid" ControlToValidate ="number" ControlToCompare ="comparenum"
Type ="Integer" ErrorMessage ="(比较错误)" runat ="server" ></asp:CompareValidator>
<br />
<asp:Label ID="label1" ForeColor ="Red" runat ="server" ></asp:Label>
</form>
</body>
</html>
怎样写才能使得dropdownlist里的第一项“等于"在第一次打开页面时可以响应呢,目前是选择后没有反应的..
谢谢大家的帮忙,小女子谢过......~~O(∩_∩)O<script language ="C#" runat ="server" > void Page_Load(object src, EventArgs e)
{
//设定比较的操作符 compvalid.Operator = (ValidationCompareOperator)opera.SelectedIndex;
} public void selected(object sender, EventArgs e)
{ Page.Validate();
if (Page.IsValid)
{
label1.Text = "已通过验证";
}
else
label1.Text = "未通过验证";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>CompareValidator控件</title>
</head>
<body>
<form id="form1" runat="server">
<table >
<tr>
<td colspan ="2" align ="center" >Compare验证控件演示</td>
</tr>
<tr>
<td>需要验证的数字:</td>
<td><asp:TextBox ID="number" runat ="server" ></asp:TextBox>
</td>
</tr>
<tr>
<td>与之比较的数字:</td>
<td><asp:TextBox ID="comparenum" runat ="server" ></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:DropDownList ID="opera" AutoPostBack ="true" OnSelectedIndexChanged ="selected" runat ="server" >
<asp:ListItem Value ="Equal" >等于</asp:ListItem>
<asp:ListItem Value ="NotEqual">不等于</asp:ListItem>
<asp:ListItem Value ="GraterThan" >大于</asp:ListItem>
<asp:ListItem Value ="GreaterThanEqual" >大于或等于</asp:ListItem>
<asp:ListItem Value ="LessThan" >小于</asp:ListItem>
<asp:ListItem Value ="LessThanEqual" >小于或等于</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
<hr />
<asp:CompareValidator ID="compvalid" ControlToValidate ="number" ControlToCompare ="comparenum"
Type ="Integer" ErrorMessage ="(比较错误)" runat ="server" ></asp:CompareValidator>
<br />
<asp:Label ID="label1" ForeColor ="Red" runat ="server" ></asp:Label>
</form>
</body>
</html>
解决方案 »
- 用户在网页上输入文本并可设置样式颜色等,最后将文本变为图片
- 同样脚本在aspx能执行在html不能执行
- 求了解System.Web.UI.Page的页面OnLoad是如何处理 <% %> 标签的
- 设置post和get的问题
- DataBinder.Eval的问题!在线等!
- 随机取得符合条件的数据
- 求一个正则表达式 ???
- 还有个问题邀请教大家,什么时候__dopostback函数asp.net才会将它加入到其生成的html页面中??最好,提供文档!谢谢
- +(加号)参数在URL中遇到的问题。
- 如何取dataset中的字段的值(等待...)
- 请教高手 新网域名查询的问题
- 如何用VMoom.Framework实现二级域名
{
//设定比较的操作符 compvalid.Operator = (ValidationCompareOperator)opera.SelectedIndex; opera.SelectValue="Equal";
}
{
//设定比较的操作符 compvalid.Operator = (ValidationCompareOperator)opera.SelectedIndex;
opera.SelectValue="Equal";
}