我编程在表格中放入4个textBox控件,希望点击提交按钮读取前两getextBox中的内容写入后两个texBox中,
WebForm1.aspx:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="test.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:Table id="Table1" style="Z-INDEX: 101; LEFT: 9px; POSITION: absolute; TOP: 8px" runat="server"></asp:Table><br>
<BR>
<asp:Button id="Button1" runat="server" Text="提交" Width="87px"></asp:Button></FONT>
</form>
</body>
</HTML>WebForm1.aspx.cs:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace test
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Table Table1;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
TableRow tRow = new TableRow();
Table1.Rows.Add(tRow);
for (int i=1;i<=4;i++)
{
TableCell tCell = new TableCell();
TextBox tTextBox = new TextBox();
tTextBox.ID="tb"+i.ToString();
tTextBox.Width=System.Web.UI.WebControls.Unit.Pixel(60);
tTextBox.Height=System.Web.UI.WebControls.Unit.Pixel(23);
tCell.Controls.Add(tTextBox);
tCell.Width=System.Web.UI.WebControls.Unit.Pixel(60);
                tRow.Cells.Add(tCell);
}

} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{

}
}
}
Button1_Click事件该如何写?我搞了半天都没有得到控件中的值。

解决方案 »

  1.   

    ((TextBox)Table1.Rows[0].Cells[2].Controls[0]).Text=((TextBox)Table1.Rows[0].Cells[0].Controls[0]).Text;
    ((TextBox)Table1.Rows[0].Cells[2].Controls[0]).Text=((TextBox)Table1.Rows[0].Cells[1].Controls[0]).Text;
      

  2.   

    错了一个字,是这样:
    ((TextBox)Table1.Rows[0].Cells[2].Controls[0]).Text=((TextBox)Table1.Rows[0].Cells[0].Controls[0]).Text;
    ((TextBox)Table1.Rows[0].Cells[3].Controls[0]).Text=((TextBox)Table1.Rows[0].Cells[1].Controls[0]).Text;在CSDN上写的,所以如果有大小写或拼写错误请见谅
      

  3.   

    附加问题:
    我用float.Parse(((TextBox)Table1.Rows[0].Cells[1].Controls[0]).Text.toString())时老是提示说输入的string格式不对,为什么?