如何得到自动生成的控件的值

hzajun 2005-04-16 12:35:20
我编程在表格中放入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事件该如何写?我搞了半天都没有得到控件中的值。

...全文
47 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
syeerzy 2005-04-16
  • 打赏
  • 举报
回复
错了一个字,是这样:
((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上写的,所以如果有大小写或拼写错误请见谅
syeerzy 2005-04-16
  • 打赏
  • 举报
回复
((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;
hzajun 2005-04-16
  • 打赏
  • 举报
回复
附加问题:
我用float.Parse(((TextBox)Table1.Rows[0].Cells[1].Controls[0]).Text.toString())时老是提示说输入的string格式不对,为什么?

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧