数据绑定实例-1
来源:互联网 发布:云终端服务器软件 编辑:程序博客网 时间:2024/05/17 02:58
数据绑定的格式
<%#operation(ddlOperator.SelectedValue) %>
新建网站:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>绑定方法调用的结果</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td colspan="2">
绑定方法调用的结果</td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td style="width: 100px">
第一个数:</td>
<td style="width: 100px">
<asp:TextBox ID="txtNum1" runat="server" Width="60px">0</asp:TextBox></td>
<td style="width: 100px">
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="txtNum1"
ErrorMessage="输入数字" Operator="DataTypeCheck" Type="Double"></asp:CompareValidator></td>
</tr>
<tr>
<td style="width: 100px">
第二个数:</td>
<td style="width: 100px">
<asp:TextBox ID="txtNum2" runat="server" Width="60px">0</asp:TextBox></td>
<td style="width: 100px">
<asp:CompareValidator ID="CompareValidator2" runat="server" ControlToValidate="txtNum2"
ErrorMessage="输入数字" Operator="DataTypeCheck" Type="Double"></asp:CompareValidator></td>
</tr>
<tr>
<td style="width: 100px; height: 24px">
运算符号:</td>
<td style="width: 100px; height: 24px">
<asp:DropDownList ID="ddlOperator" runat="server">
<asp:ListItem>--请选择运算符号--</asp:ListItem>
<asp:ListItem>+</asp:ListItem>
<asp:ListItem>-</asp:ListItem>
<asp:ListItem>*</asp:ListItem>
<asp:ListItem>/</asp:ListItem>
</asp:DropDownList></td>
<td style="width: 100px; height: 24px">
</td>
</tr>
<tr>
<td style="width: 100px">
</td>
<td style="width: 100px">
<asp:Button ID="btnOk" runat="server" Text="确定" /></td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td style="width: 100px">
运算结果:</td>
<td style="width: 100px">
<asp:Label ID="Label1" runat="server" Text='<%#operation(ddlOperator.SelectedValue) %>'/></td>
<td style="width: 100px">
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
后台代码:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Page.DataBind();
}
public string operation(string VarOperator)
{
double num1=Convert.ToDouble (txtNum1.Text);
double num2=Convert.ToDouble (txtNum2.Text);
double result = 0;
switch (VarOperator)
{
case "+":
result = num1 + num2;
break ;
case "-":
result = num1 - num2;
break ;
case "*":
result = num1 * num2;
break ;
case "/":
result = num1 / num2;
break ;
}
return result.ToString ();
}
}
- 数据绑定实例-1
- 入门-WPF数据绑定-实例
- WPF ListView绑定数据实例
- ng-model数据绑定实例
- WPF 简单数据绑定实例
- ComboBox数据绑定的一个实例
- TreeView绑定数据库中的数据实例
- WinForm DataGridViewComboCell数据绑定、事件机制实例
- zk 数据绑定实例(grid嵌套)
- android实例 listview与sqlite数据绑定
- android实例 listview与sqlite数据绑定
- android实例 listview与sqlite数据绑定
- angular双向数据绑定实例代码
- IOS学习笔记-UITableView绑定数据实例
- Java EE - Spring MVC 数据绑定实例
- WPF数据绑定(1-简单数据绑定)
- 2.vue.js实例:双向数据绑定实例
- WPF 数据绑定[1]
- python 数据处理清洗
- 如何做汇报
- 安装 IDEA、安装 Scala 插件以及导入 Spark 源码
- mac版MySQL初始密码
- 插入加减号使结果为110
- 数据绑定实例-1
- 求一个整数的质因数的代码(核心部分)
- 几个经典递推关系
- 经典算法——调整数组顺序使奇数位于偶数前面
- 区间第K大数
- MySQl索引原理
- 项目经理沟通技巧
- IDEA导入jar包
- (3)排序算法——冒泡排序