28,390
社区成员
发帖
与我相关
我的任务
分享
TextBox txtXuhao { get; set; }
DropDownList dptea { get; set; }
TextBox txtBegin { get; set; }
TextBox txtEnd { get; set; }
TextBox txtCode { get; set; }
//动态生成控件
public void CreateControl()
{
if (ViewState["CreateControl"] == null) return;
int claId = Convert.ToInt32(Request.QueryString["claID"]);
DataSet dsDeta = tb.ShowClassDetail(claId);
TableRow row1 = new TableRow();
TableCell cell1 = new TableCell();
Label la = new Label();
la.Text = "班次序号";
la.Width = 82;
Label la2 = new Label();
la2.Text = "老师";
la2.Width = 125;
Label la3 = new Label();
la3.Text = "上课开始时间";
la3.Width = 210;
Label la4 = new Label();
la4.Text = "下课结束时间";
la4.Width = 210;
Label la5 = new Label();
la5.Text = "课程代码";
la5.Width = 200;
cell1.Controls.Add(la);
cell1.Controls.Add(la2);
cell1.Controls.Add(la3);
cell1.Controls.Add(la4);
cell1.Controls.Add(la5);
row1.Cells.Add(cell1);
HolderTable.Rows.Add(row1);
for (int i = 0; i < dsDeta.Tables[0].Rows.Count; i++)
{
TableRow row = new TableRow();
TableCell cell = new TableCell();
txtXuhao = new TextBox();
txtXuhao.Width = 78;
txtXuhao.ID = "txtXuhao" + i;
dptea = new DropDownList();
dptea.ID = "dptea" + i;
dptea.Width = 120;
dptea.DataSource = teab.showTeacherProFile();
dptea.DataTextField = "Teacher_Name";
dptea.DataValueField = "Teacher_ID";
dptea.DataBind();
txtBegin = new TextBox();
txtBegin.ID = "txtBegin" + i;
txtBegin.Width = 200;
txtEnd = new TextBox();
txtEnd.ID = "txtEnd" + i;
txtEnd.Width = 200;
txtCode = new TextBox();
txtCode.ID = "txtCode" + i;
txtCode.Width = 180;
cell.Controls.Add(txtXuhao);
cell.Controls.Add(dptea);
cell.Controls.Add(txtBegin);
cell.Controls.Add(txtEnd);
cell.Controls.Add(txtCode);
row.Cells.Add(cell);
HolderTable.Rows.Add(row);
txtXuhao.Text = dsDeta.Tables[0].Rows[i]["Class_Sequence"].ToString();
txtBegin.Text = dsDeta.Tables[0].Rows[i]["Class_Time_Begin"].ToString();
txtEnd.Text = dsDeta.Tables[0].Rows[i]["Class_Time_End"].ToString();
txtCode.Text = dsDeta.Tables[0].Rows[i]["Course_Code"].ToString();
}
}
static TextBox txXuhao;
static DropDownList dpte;
static TextBox txtBe;
static TextBox txten;
static TextBox txtco;
public void save()
{
CreateControl();
for (int i = 0; i < dsDeta.Tables[0].Rows.Count; i++)
{
txXuhao = this.form1.FindControl("txtXuhao"+i) as TextBox;
int a =Convert.ToInt32(txXuhao.Text.ToString());
dpte = this.form1.FindControl("dptea" + i) as DropDownList;
int b =Convert.ToInt32(dpte.SelectedValue);
txtBe = this.form1.FindControl("txtBegin"+i) as TextBox;
DateTime c = Convert.ToDateTime(txtBe.Text);
txten = this.form1.FindControl("txtEnd" + i) as TextBox;
DateTime d = Convert.ToDateTime(txten.Text);
txtco = this.form1.FindControl("txtCode" + i) as TextBox;
string e = txtco.Text;
}
}
if(!Ispostback)
{
if (ViewState["CreateControl"] == null)
{
ViewState["CreateControl"] = true;
CreateControl();
}
}