aspx 文件如下
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="YuanPayrollsEdit.aspx.cs" Inherits="YuanPayrollsEdit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script language="javascript" type="text/javascript">
// <!CDATA[
 function CheckInput(val,id) {
     //alert(id);
butSave_Click
     if (event.keyCode == 13)
 { 
//;
//float tlb_sum= 0.00f;
//String add_js = (Label)Table1.FindControl("Label_add")).Text.tostring();
//decimal tlb_sum = decimal.Parse(((Label)Table1.FindControl("Label_add")).Text);

event.keyCode = 9;//回车转变成tab
}

  
 //判断输入是否为0-9 (小键盘和大键盘)*2
 else if ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105))
         return true;  //判断输入的 是否是 .(主键盘和小键盘)*2 Home End delete left right backspace
     else if (event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 190 || event.keyCode == 35 || event.keyCode == 36 || event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 110 )
         return true;
     
 else
         return false;
 } function CheckOutput(val) {
//float je = float.Parse(val);
//decimal je = 0.00m;
//je = decimal.Parse(val);
//alert(je);
 }function butSelect_onclick() {
    var strselect;
    var strYuan = window.showModalDialog("Dialog/Yuan.aspx",strselect,"status:no;resizable:no;dialogwidth:420px;dialogheight:250px");
if (strYuan != null)
{
var Yuan_ID = document.getElementById ('ctl00$ContentPlaceHolder1$Yuan_ID');
Yuan_ID.value = strYuan.Yuan_ID;

var Yuan_Name = document.getElementById ('ctl00$ContentPlaceHolder1$Yuan_Name');
Yuan_Name.value = strYuan.Yuan_Name;
}
}function butDepartment_onclick() {
    var strselect;
    var strDepartment = window.showModalDialog("Dialog/Department.aspx",strselect,"status:no;resizable:no;dialogwidth:420px;dialogheight:250px");
if (strDepartment != null)
{
var Department_ID = document.getElementById ('ctl00$ContentPlaceHolder1$Department_ID');
Department_ID.value = strDepartment.Department_ID;

var Department_Name = document.getElementById ('ctl00$ContentPlaceHolder1$Department_Name');
Department_Name.value = strDepartment.Department_Name;
}
}function butJob_onclick() {
    var strselect;
    var strJob = window.showModalDialog("Dialog/Job.aspx",strselect,"status:no;resizable:no;dialogwidth:420px;dialogheight:250px");
if (strJob != null)
{
var Job_ID = document.getElementById ('ctl00$ContentPlaceHolder1$Job_ID');
Job_ID.value = strJob.Job_ID;

var Job_Name = document.getElementById ('ctl00$ContentPlaceHolder1$Job_Name');
Job_Name.value = strJob.Job_Name;
}
}function butDate_onclick() {
    var strselect = "选择日期";
    var strdate = window.showModalDialog("calendar/index.html",strselect,"status:no;resizable:no;dialogwidth:400px;dialogheight:250px");
if (strdate != null)
{
var Yuan_Remove_Date = document.getElementById ('ctl00$ContentPlaceHolder1$Yuan_Remove_Date');
Yuan_Remove_Date.value = strdate.date;
}
}// ]]>
</script>
        <div class="c_MainLeft">
<ul style="text-align:left;">
    <li style="list-style-type: none;height:130px;">
        <img src="images/038.png" alt="说明"/></li><li style="list-style-type: none;height:40px;">
    共有<asp:Label ID="lbl_Count" runat="server" Style="color: red"></asp:Label>条发放记录</li><li style="list-style-type: none;height:40px;"><asp:TextBox ID="Yuan_Name" runat="server"
            CssClass="c_input" style="width: 80px"></asp:TextBox>
        <input id="butYuan" class="c_button" name="butYuan" style="width: 30px" type="button"
            value="..." onclick="return butYuan_onclick()" />
        <asp:HiddenField ID="Yuan_ID" runat="server" />
    </li>
<li style="list-style-type: none;height:40px;padding:0px;">
                <asp:Button ID="Button1" runat="server" CssClass="c_button" Text="按员工查询" OnClick="butYuan_Click" />
                <asp:Button ID="butAll" runat="server" CssClass="c_button" Text="查询全部" OnClick="butAll_Click" /></li></ul>
        </div>
    <div class = "c_MainRight" style="text-align:left " >
       <fieldset class="c_edit">
<legend>员工工资明细信息</legend>

          <asp:Button ID="butSave" runat="server" CssClass="c_button" Text="保存" OnClick="butSave_Click" />
                &nbsp;&nbsp;&nbsp;&nbsp;
          <asp:Button ID="butReturn" runat="server" CssClass="c_button" Text="返回" OnClick="butReturn_Click" /> <ul>
<asp:Table id="Table1" 
             style="Z-INDEX: 101; POSITION: absolute; " runat="server" ></asp:Table>
        </ul>

<ul>
            <asp:HiddenField ID="Hid_Command" runat="server" />
            <asp:HiddenField ID="Hid_RowIndex" runat="server" />
        </ul>
         </fieldset>   
   </div>
        
</asp:Content>

解决方案 »

  1.   

    cs 文件 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 YuanPayrollsEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int intRowsIndex = 0;
                if (Request.QueryString["RowIndex"] != null)
                {
                    intRowsIndex = int.Parse(Request.QueryString["RowIndex"].ToString());
                    Hid_RowIndex.Value = intRowsIndex.ToString();
                }
                String strCommand = "";
                if (Request.QueryString["Command"] != null)
                {
                    strCommand = Request.QueryString["Command"].ToString();
                    Hid_Command.Value = strCommand;
                } if (strCommand == "UPdate")
                {
                    Yuan_PayrollsEdit yuan_payrollsEdit = new Yuan_PayrollsEdit();
                    DataSet ds_Yuan_payrollsEdit = yuan_payrollsEdit.GetDataSet("", "");
                    string aa = ds_Yuan_payrollsEdit.Tables["T_Yuan_payrollsEdit"].Rows.Count.ToString();
                    TableRow tr = new TableRow();
                    TableCell tc;
                    TableCell cell;
                    TextBox tc1;
                    int i ;
    for (i = 0; i < int.Parse(aa); i++)
                    {
                        if ( i == 0)
                        {
                            tr = new TableRow();
    tc = new TableCell();
    tc.ID = "Label"+ i.ToString();
    cell = new TableCell();
    tc1 = new TextBox();
    tc1.ID = "TextBox" + i.ToString();
    tc1.Columns = 10;
    //tc1.Font.Size= 12;
    //tc1.Font.Bold = true;
    //tc1.Height = 20;
    tc1.CssClass = "c_textbox";
    tc.CssClass = "c_label";
    tc1.Text = ds_Yuan_payrollsEdit.Tables["T_Yuan_payrollsEdit"].Rows[i][2].ToString();
    //tc.Font.Bold = false;
    //tc.Font.Size = 12;
    tc.Text = ds_Yuan_payrollsEdit.Tables["T_Yuan_payrollsEdit"].Rows[i][1].ToString() + ":    ";
    tr.Cells.Add(tc);
    cell.Controls.Add(tc1);
    tr.Cells.Add(cell);
    Table1.Rows.Add(tr);
    }
    if (i % 3 == 0 && i != 0)
                            tr = new TableRow();
                        tc = new TableCell();
                        tc.ID = "Label"+ i.ToString();
    cell = new TableCell();
                        tc1 = new TextBox();
                        tc1.ID = "TextBox" + i.ToString();
                        tc1.Columns = 10;
                        //tc1.Font.Size= 12;
                        //tc1.Font.Bold = true;
                        //tc1.Height = 20;
                        tc1.CssClass = "c_textbox";
                        tc.CssClass = "c_label";
                        tc1.Text = ds_Yuan_payrollsEdit.Tables["T_Yuan_payrollsEdit"].Rows[i][2].ToString();
                        //tc.Font.Bold = false;
                        //tc.Font.Size = 12;
                        tc.Text = ds_Yuan_payrollsEdit.Tables["T_Yuan_payrollsEdit"].Rows[i][1].ToString() + ":    ";
                        tr.Cells.Add(tc);
                        cell.Controls.Add(tc1);
                        tr.Cells.Add(cell);                    if (i % 3 == 0)
                        {
                            Table1.Rows.Add(tr);
                        }
                    }
                    if (i % 3 != 0)
                        Table1.Rows.Add(tr);            } 
     if (strCommand == "Edit")
            {
                   //权限查询
                 publicFunction pFunction = new publicFunction();            PayrollEdit("add", intRowsIndex,2);
                this.Table1.FindControl("textid0").Focus();
    } }
        }
        protected void PayrollEdit(string str,int intRowsIndex,int js)
        {
    if (str == "add")
            {
                //获得数据表
                DataTable T_Yuan_payrolls = (DataTable)Session["T_Yuan_payrolls"];
                String Edit_date = T_Yuan_payrolls.Rows[intRowsIndex]["Date"].ToString();
                String Edit_Name = T_Yuan_payrolls.Rows[intRowsIndex]["Name"].ToString();            //建立数据源
                Yuan_PayrollsEdit yuan_payrollsEdit = new Yuan_PayrollsEdit();
                DataSet ds_Yuan_payrollsEdit = yuan_payrollsEdit.GetDataSet(Edit_date, Edit_Name);            string aa = ds_Yuan_payrollsEdit.Tables["T_Yuan_payrollsEdit_add"].Rows.Count.ToString();
                TableRow tr = new TableRow();
                TableCell tc;
                TableCell cell;
                TextBox tc1;
                int i = 0;
                decimal sum_je = 0.00m;
                for (i = 0; i < int.Parse(aa); i++)
                {
                    if (i == 0)
                    {
                        tr = new TableRow();
                        //tr = new TableRow();
                        tc = new TableCell();
                        cell = new TableCell();
                        Label tcc = new Label();
                        Label tcc1 = new Label();
                        tc.ID = "Labeltop";//发放日期
                        tcc.ID = "Tlbtop";//发放姓名
                        tcc1.ID = "Label_add";//发放项目计数
                        tc.Text = Edit_date;
                        tcc.Text = Edit_Name.Remove(0, 6);
                        tcc1.Text = aa;
                        tcc1.Visible = false;
                        tc.CssClass = "c_label";
                        tcc.CssClass = "c_label";
                        tr.Cells.Add(tc);
                        cell.Controls.Add(tcc);
                        cell.Controls.Add(tcc1);
                        tr.Cells.Add(cell);
                        Table1.Rows.Add(tr);                }
                    if (i % js == 0)
                        tr = new TableRow();
                    
    tc = new TableCell();
                    tc.ID = "Label" + ds_Yuan_payrollsEdit.Tables["T_Yuan_payrollsEdit_add"].Rows[i][0].ToString();
                    cell = new TableCell();
                    tc1 = new TextBox();
    tc1.ID = "textid" + i.ToString();
                    tc1.Columns = 8;
                    tc1.CssClass = "c_textbox";
                    tc.CssClass = "c_label";
                    tc1.Text = ds_Yuan_payrollsEdit.Tables["T_Yuan_payrollsEdit_add"].Rows[i][2].ToString();
                    sum_je += decimal.Parse(ds_Yuan_payrollsEdit.Tables["T_Yuan_payrollsEdit_add"].Rows[i][2].ToString());
                    tc.Text = ds_Yuan_payrollsEdit.Tables["T_Yuan_payrollsEdit_add"].Rows[i][1].ToString() + ":    ";
                    //tc1.Attributes.Add("onkeydown", "if(event.keyCode==13)event.keyCode=9");
                    tc1.Attributes.Add("onkeydown", "return CheckInput(this.value,this.id)");
    //tc1.Attributes.Add("onblur", "alert(\"OK\")");
    //tc1.Attributes.Add("onblur", "CheckOutput(this.value,)");
    //tc1.Attributes.Add("lostfocus", "alert(this.value)");
    //tc1.Attributes.Add("ValidationExpression" ,"/^[0-9]{1,5}([.]{1}[0-9]{1,2})?$/");
    tr.Cells.Add(tc);
                    cell.Controls.Add(tc1);
                    /*添加正则表达式
    RegularExpressionValidator tc1_VE = new RegularExpressionValidator(); 
    tc1_VE.ControlToValidate   =   tc1.ID;
    tc1_VE.ValidationExpression = "^[0-9]\d{0,4}*\.\d{0,2}$|^\d*$";
    tc1_VE.ErrorMessage   =   "请输入数字! "; 
    cell.Controls.Add(tc1_VE);
    */
                    tr.Cells.Add(cell);

                    if (i % js == 0)
                    {
                        Table1.Rows.Add(tr);
                    }
                }
                if (i % js != 0)
                    Table1.Rows.Add(tr);
                tr = new TableRow();
                tc = new TableCell();
                tc.ID = "Labelsum";
                cell = new TableCell();
                Label sum_tcc = new Label();
                Label sum_tcc1 = new Label();
                sum_tcc.ID = "Tlbsum";
                tc.Text = "小  计:";
                sum_tcc.Width = 95;
                sum_tcc.Text = sum_je.ToString();
                sum_tcc1.Text = aa;
                sum_tcc1.Visible = false;
                tc.CssClass = "c_label_sum";
                sum_tcc.CssClass = "c_label_sum";
                tr.Cells.Add(tc);
                cell.Controls.Add(sum_tcc);
                cell.Controls.Add(sum_tcc1);
                tr.Cells.Add(cell);
                Table1.Rows.Add(tr);
            }
             }    }
        protected void butSave_Click(object sender, EventArgs e)
        {
     
        }
        protected void butReturn_Click(object sender, EventArgs e)
        {
            Response.Redirect("YuanPayrollsView.aspx");
        }
        protected void butYuan_Click(object sender, EventArgs e)
        {    }
        protected void Yuan_ID_ValueChanged(object sender, EventArgs e)
        {    }
        protected void butAll_Click(object sender, EventArgs e)
        {    }}
      

  2.   

    我想问下 如何 在 这些 textbox 得到回车按键后,对textbox总的输入进行判断,并将这些自动生成的textbox的值 进行累加,将值回写到textbox ID = Tlbsum 的 这个textbox中。我原本是想写在 function CheckInput(val,id) {} 这里的 可 只要写入  float tlb_sum= 0.00f; 这句 整个页面就消失了 而不是 跳到下一个textbox框,注释掉 只留下 event.keyCode = 9; 就没问题  求教了 谢谢 
      

  3.   

    谢谢 楼上的回答 ,我的累加是在用户修改textbox的值并按回车后,重新对自动生成的所有的textbox进行累加,并将结果放入一个特定的texbox中,如何遍历,我知道如何改 ,可就是不知道咋调用,写入那个事件中, 试过正则表达式,onblur 事件 都不能实现 所有 发帖求方法!