源码如下
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;
using AMDSchool.School.Common.Data;
using AMDSchool.School.BusinessFacade;namespace AMDSchool.WebUI.Task
{
public partial class StudentDailyOnline : AMDSchool.WebCommon.DefaultPageBase
{
Guid userID;
Guid cookieCompanyID;
StudentDailyReportInputData data;
protected void Page_Load(object sender, EventArgs e)
{
LabelNews.Text = DateTime.Now.ToShortDateString();
userID = Bluematrix.Framework.Web.Intergrated.IntergratedSession.CurrentUser.Id;
cookieCompanyID = AMDSchool.WebCommon.WebCommonConfigManager.CurrentCompanyID;
if (!Page.IsPostBack)
{
BmTableSMS.SortColumnName = "Time";
BmTableSMS.IsSortDesc = true;
BmTableSMS.SortImageUrl = "/WebCommon/Images/BmTable/up.GIF";
BmTableSMS.SortDescImageUrl = "/WebCommon/Images/BmTable/down.GIF";
}
} protected override void OnInit(EventArgs e)
{
BmTableSMS.HeadCellClicked += new Bluematrix.WebControls.BmTable.HeadCellClickedHandler(BmTableSMS_HeadCellClicked);
base.OnInit(e);
} protected override void OnPreRender(EventArgs e)
{
ShowTable();
base.OnPreRender(e);
} void BmTableSMS_HeadCellClicked(object sender, Bluematrix.WebControls.SortEventArgs e)
{
BmTableSMS.IsSortDesc = e.IsSortDesc;
BmTableSMS.SortColumnName = e.FieldName;
} private void ShowTable()
{
BmTableSMS.Clear();
BmTableSMS.BodyWidth = "100%";
using (data = new StudentDailyReportSystem().GetDailyReportByUserID(cookieCompanyID, userID))
{
TableHeaderRow headRow = BmTableSMS.AddHeadRow();
BmTableSMS.AddHeadCell(headRow, "编号", "20%").HorizontalAlign = HorizontalAlign.Center;
BmTableSMS.AddHeadCell(headRow, "产品型号", "20%").HorizontalAlign = HorizontalAlign.Center;
BmTableSMS.AddHeadCell(headRow, "销量", "20%").HorizontalAlign = HorizontalAlign.Center;
BmTableSMS.AddHeadCell(headRow, "库存", "20%").HorizontalAlign = HorizontalAlign.Center;
if (data == null || data.StudentDailyReportInput.Count == 0)
return;
this.rowCount.Value = data.StudentDailyReportInput.Count.ToString();
TableRow bodyRow;
TableCell bodyCell;
string cellText;
for (int i = 0; i < data.StudentDailyReportInput.Count; i++)
{
bodyRow = BmTableSMS.AddBodyRow();
bodyCell = BmTableSMS.AddCell(bodyRow, data.StudentDailyReportInput[i].Code, HorizontalAlign.Center);
bodyCell = BmTableSMS.AddCell(bodyRow, data.StudentDailyReportInput[i].Model, HorizontalAlign.Center);
if (data.StudentDailyReportInput[i].Stocks != null)
{
TextBox textBox = new TextBox();
textBox.Width = 30;
textBox.ID = "stocks" + i.ToString();
textBox.Text = data.StudentDailyReportInput[i].Stocks;
//cellText = string.Format("<input style=\"width:30px\" name=\"stocks" + i + "\" value= \"" + data.StudentDailyReportInput[i].Stocks + "\" />");
bodyCell = BmTableSMS.AddCell(bodyRow, "", HorizontalAlign.Center);
bodyCell.Controls.Add(textBox);
}
else
{
TextBox textBox = new TextBox();
textBox.Width = 30;
textBox.ID = "stocks" + i.ToString();
textBox.Text = "";
//cellText = string.Format("<input style=\"width:30px\" id=\"stocks" + i + "\" value= \"\" />");
bodyCell = BmTableSMS.AddCell(bodyRow, "", HorizontalAlign.Center);
bodyCell.Controls.Add(textBox);
}
if (data.StudentDailyReportInput[i].Sale != null)
{
TextBox textBox = new TextBox();
textBox.Width = 30;
textBox.ID = "sale" + i;
textBox.Text = data.StudentDailyReportInput[i].Sale;
//cellText = string.Format("<input style=\"width:30px\" id=\"sale" + i + "\" value= \"" + data.StudentDailyReportInput[i].Sale + "\" />");
bodyCell = BmTableSMS.AddCell(bodyRow, "", HorizontalAlign.Center);
bodyCell.Controls.Add(textBox);
}
else
{
TextBox textBox = new TextBox();
textBox.Width = 30;
textBox.ID = "sale" + i;
textBox.Text = "";
//cellText = string.Format("<input style=\"width:30px\" id=\"sale" + i + "\" value= \"\" />");
bodyCell = BmTableSMS.AddCell(bodyRow, "", HorizontalAlign.Center);
bodyCell.Controls.Add(textBox);
}
}
}
} protected void button1_Click(object sender, EventArgs e)
{
int count = Convert.ToInt32(this.rowCount.Value);
//data = new StudentDailyReportSystem().GetDailyReportByUserID(cookieCompanyID, userID);
//string str;
//string stocks;
//string sale;
for (int i = 0; i < count; i++)
{
TextBox tb = (TextBox)this.FindControl("stocks" + i.ToString());
string ss = tb.Text;
}
// //string sss = tb.Text;
// //stocks = "0";
// //sale = "0";
// //str = "stocks" + i;
// //ClientScript.RegisterStartupScript(this.GetType(), "ccc", "<script>getValue('" + str + "')</script>");
// //stocks = this.valuehidden.Value.Trim();
// //str = "sale" + i;
// //ClientScript.RegisterStartupScript(this.GetType(), "ccc", "<script>getValue('" + str + "')</script>");
// //sale = this.valuehidden.Value.Trim(); // //if (stocks == "" && sale == "")
// //{
// // //data.StudentDailyReportInput[i].i
// //}
// //else
// //{
// // data.StudentDailyReportInput[i].Stocks = stocks;
// // data.StudentDailyReportInput[i].Sale = sale;
// //}
//new StudentDailyReportSystem().UpdateDailyReport(data);
} protected void button2_Click(object sender, EventArgs e)
{
Response.Redirect("DailyReport.aspx");
}
}
}
页面加载后,动态的textbox赋值正确,点button1后,取textbox得新值,取不到动态生成的控件了
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;
using AMDSchool.School.Common.Data;
using AMDSchool.School.BusinessFacade;namespace AMDSchool.WebUI.Task
{
public partial class StudentDailyOnline : AMDSchool.WebCommon.DefaultPageBase
{
Guid userID;
Guid cookieCompanyID;
StudentDailyReportInputData data;
protected void Page_Load(object sender, EventArgs e)
{
LabelNews.Text = DateTime.Now.ToShortDateString();
userID = Bluematrix.Framework.Web.Intergrated.IntergratedSession.CurrentUser.Id;
cookieCompanyID = AMDSchool.WebCommon.WebCommonConfigManager.CurrentCompanyID;
if (!Page.IsPostBack)
{
BmTableSMS.SortColumnName = "Time";
BmTableSMS.IsSortDesc = true;
BmTableSMS.SortImageUrl = "/WebCommon/Images/BmTable/up.GIF";
BmTableSMS.SortDescImageUrl = "/WebCommon/Images/BmTable/down.GIF";
}
} protected override void OnInit(EventArgs e)
{
BmTableSMS.HeadCellClicked += new Bluematrix.WebControls.BmTable.HeadCellClickedHandler(BmTableSMS_HeadCellClicked);
base.OnInit(e);
} protected override void OnPreRender(EventArgs e)
{
ShowTable();
base.OnPreRender(e);
} void BmTableSMS_HeadCellClicked(object sender, Bluematrix.WebControls.SortEventArgs e)
{
BmTableSMS.IsSortDesc = e.IsSortDesc;
BmTableSMS.SortColumnName = e.FieldName;
} private void ShowTable()
{
BmTableSMS.Clear();
BmTableSMS.BodyWidth = "100%";
using (data = new StudentDailyReportSystem().GetDailyReportByUserID(cookieCompanyID, userID))
{
TableHeaderRow headRow = BmTableSMS.AddHeadRow();
BmTableSMS.AddHeadCell(headRow, "编号", "20%").HorizontalAlign = HorizontalAlign.Center;
BmTableSMS.AddHeadCell(headRow, "产品型号", "20%").HorizontalAlign = HorizontalAlign.Center;
BmTableSMS.AddHeadCell(headRow, "销量", "20%").HorizontalAlign = HorizontalAlign.Center;
BmTableSMS.AddHeadCell(headRow, "库存", "20%").HorizontalAlign = HorizontalAlign.Center;
if (data == null || data.StudentDailyReportInput.Count == 0)
return;
this.rowCount.Value = data.StudentDailyReportInput.Count.ToString();
TableRow bodyRow;
TableCell bodyCell;
string cellText;
for (int i = 0; i < data.StudentDailyReportInput.Count; i++)
{
bodyRow = BmTableSMS.AddBodyRow();
bodyCell = BmTableSMS.AddCell(bodyRow, data.StudentDailyReportInput[i].Code, HorizontalAlign.Center);
bodyCell = BmTableSMS.AddCell(bodyRow, data.StudentDailyReportInput[i].Model, HorizontalAlign.Center);
if (data.StudentDailyReportInput[i].Stocks != null)
{
TextBox textBox = new TextBox();
textBox.Width = 30;
textBox.ID = "stocks" + i.ToString();
textBox.Text = data.StudentDailyReportInput[i].Stocks;
//cellText = string.Format("<input style=\"width:30px\" name=\"stocks" + i + "\" value= \"" + data.StudentDailyReportInput[i].Stocks + "\" />");
bodyCell = BmTableSMS.AddCell(bodyRow, "", HorizontalAlign.Center);
bodyCell.Controls.Add(textBox);
}
else
{
TextBox textBox = new TextBox();
textBox.Width = 30;
textBox.ID = "stocks" + i.ToString();
textBox.Text = "";
//cellText = string.Format("<input style=\"width:30px\" id=\"stocks" + i + "\" value= \"\" />");
bodyCell = BmTableSMS.AddCell(bodyRow, "", HorizontalAlign.Center);
bodyCell.Controls.Add(textBox);
}
if (data.StudentDailyReportInput[i].Sale != null)
{
TextBox textBox = new TextBox();
textBox.Width = 30;
textBox.ID = "sale" + i;
textBox.Text = data.StudentDailyReportInput[i].Sale;
//cellText = string.Format("<input style=\"width:30px\" id=\"sale" + i + "\" value= \"" + data.StudentDailyReportInput[i].Sale + "\" />");
bodyCell = BmTableSMS.AddCell(bodyRow, "", HorizontalAlign.Center);
bodyCell.Controls.Add(textBox);
}
else
{
TextBox textBox = new TextBox();
textBox.Width = 30;
textBox.ID = "sale" + i;
textBox.Text = "";
//cellText = string.Format("<input style=\"width:30px\" id=\"sale" + i + "\" value= \"\" />");
bodyCell = BmTableSMS.AddCell(bodyRow, "", HorizontalAlign.Center);
bodyCell.Controls.Add(textBox);
}
}
}
} protected void button1_Click(object sender, EventArgs e)
{
int count = Convert.ToInt32(this.rowCount.Value);
//data = new StudentDailyReportSystem().GetDailyReportByUserID(cookieCompanyID, userID);
//string str;
//string stocks;
//string sale;
for (int i = 0; i < count; i++)
{
TextBox tb = (TextBox)this.FindControl("stocks" + i.ToString());
string ss = tb.Text;
}
// //string sss = tb.Text;
// //stocks = "0";
// //sale = "0";
// //str = "stocks" + i;
// //ClientScript.RegisterStartupScript(this.GetType(), "ccc", "<script>getValue('" + str + "')</script>");
// //stocks = this.valuehidden.Value.Trim();
// //str = "sale" + i;
// //ClientScript.RegisterStartupScript(this.GetType(), "ccc", "<script>getValue('" + str + "')</script>");
// //sale = this.valuehidden.Value.Trim(); // //if (stocks == "" && sale == "")
// //{
// // //data.StudentDailyReportInput[i].i
// //}
// //else
// //{
// // data.StudentDailyReportInput[i].Stocks = stocks;
// // data.StudentDailyReportInput[i].Sale = sale;
// //}
//new StudentDailyReportSystem().UpdateDailyReport(data);
} protected void button2_Click(object sender, EventArgs e)
{
Response.Redirect("DailyReport.aspx");
}
}
}
页面加载后,动态的textbox赋值正确,点button1后,取textbox得新值,取不到动态生成的控件了
this.Controls.Find("stocks" + i.ToString(),true);
试试
然后根据这个规律,从Controls中获取