62,046
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!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>
<asp:DataGrid ID="Grid1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="price" HeaderText="Price"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Quantity">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("quantity") %>' onkeyup="workout(this)"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="sum" HeaderText="Sum"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
</div>
</form>
<script type="text/javascript">
var isIe=window.navigator.appName.indexOf("Netscape") == -1?true:false;
function accMul(arg1,arg2){
var m=0,s1=arg1.toString(),s2=arg2.toString();
try{m+=s1.split(".")[1].length}catch(e){}
try{m+=s2.split(".")[1].length}catch(e){}
return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)
}
function workout(oSrc){
var oCells=oSrc.parentNode.parentNode.getElementsByTagName("td");
var sPrice=isIe?oCells[0].innerText:oCells[0].textContent;
var iSum=accMul(sPrice,oSrc.value);
if(isIe)
oCells[2].innerText=iSum;
else
oCells[2].textContent=iSum;
}
</script>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Grid1.DataSource = GenerateTable();
Grid1.DataBind();
}
}
private DataTable GenerateTable()
{
DataTable dt = new DataTable();
dt.Columns.Add("Price", typeof(double));
dt.Columns.Add("Quantity", typeof(int));
dt.Columns.Add("Sum", typeof(int));
DataRow row;
Random rnd = new Random();
for (int i = 1; i != 31; ++i)
{
row = dt.NewRow();
row[0] = rnd.Next(1, 273) / 2.0;
row[1] = rnd.Next(0, 87);
row[2] = 1;
row[2] = (double)row[0] * (int)row[1];
dt.Rows.Add(row);
}
return dt;
}
}