是以前完成一段程序,当初想了很久参考了老师的代码,完成了自己要求的功能.主要是代码片段
List<TextBox> textlist = new List<TextBox>(); //...
buildtableshow(TableShow, 100000);
buildIlist(TableShow);
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
protected bool setPageinfoToClass()
{
try
{
return pkhead.p_storePageinfoToClass(hfpkhead_id.Value,kpDDLEditTeacher.seleValue,kpDDLEditLesson.seleValue,txtEditMembers.Text
,txtEditStartweek.Text,txtEditEndweek.Text,txtEditPrelection.Text
,kpDDLEditWeektype.seleValue,txtEditWeekhour.Text,kpDDLEditClaroomtye.seleValue
,kpDDLOtherSucc.seleValue,kpDDLGroupcode.seleValue,txtEditGroupwith.Text,txtEditTeacherlist.Text
,textlist[0].Text,textlist[1].Text,textlist[2].Text,textlist[3].Text,textlist[4].Text
,textlist[5].Text,textlist[6].Text,textlist[7].Text,textlist[8].Text,textlist[9].Text
,textlist[10].Text,textlist[11].Text,textlist[12].Text,textlist[13].Text,textlist[14].Text
,textlist[15].Text,textlist[16].Text,textlist[17].Text,textlist[18].Text,textlist[19].Text
,textlist[20].Text,textlist[21].Text,textlist[22].Text,textlist[23].Text,textlist[24].Text
,textlist[25].Text,textlist[26].Text,textlist[27].Text,textlist[28].Text,textlist[29].Text
,textlist[30].Text,textlist[31].Text,textlist[32].Text,textlist[33].Text,textlist[34].Text
,kpDDLDeptEdit.seleValue);
}
catch (Exception ex) { labelErrinfo.Text = "所提交的数据无法保存。请检查数据格式" + ex.Message; return false; }
}
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
protected void buildtableshow(Table table, int id)
{
dbb = new DBBase();
string sql = string.Format("select * from pkhead where pkhead_id={0}", id);
DataSet ds = dbb.readData(sql);
TableRow tr = new TableRow();
foreach (DataRow dr in ds.Tables[0].Rows)
{
table.Rows.Clear();
tr.Cells.Add(newcell("时 间"));
tr.Cells.Add(newcell("星期一"));
tr.Cells.Add(newcell("星期二"));
tr.Cells.Add(newcell("星期三"));
tr.Cells.Add(newcell("星期四"));
tr.Cells.Add(newcell("星期五"));
tr.Cells.Add(newcell("星期六"));
tr.Cells.Add(newcell("星期天"));
table.Rows.Add(tr);
tr = new TableRow();
int ss = 1;
for (int i = 1; i <= 5; i++)
{
tr.Cells.Add(newcell(string.Format("{0}、{1}节",ss,ss+1)));
ss=ss+2;
for (int j = 0; j <= 30; j = j + 5)
{
string name = "t" + pubfunc.NumToStrPrefix0(i + j, 2);
string content = pubfunc.ObjectToString(dr[name]);
tr.Cells.Add(newcell(CreateTextbox(name,content)));
}
tr.EnableViewState = true;
table.Rows.Add(tr);
tr = new TableRow();
}
tr.EnableViewState = true;
table.Rows.Add(tr);
table.EnableViewState = true;
}
table.Visible = true;
table.BackColor = System.Drawing.Color.AntiqueWhite;
if (ds != null) ds.Dispose();
}
protected void buildtableshow(Table table)
{
TableRow tr = new TableRow();
table.Rows.Clear();
tr.Cells.Add(newcell("时 间"));
tr.Cells.Add(newcell("星期一"));
tr.Cells.Add(newcell("星期二"));
tr.Cells.Add(newcell("星期三"));
tr.Cells.Add(newcell("星期四"));
tr.Cells.Add(newcell("星期五"));
tr.Cells.Add(newcell("星期六"));
tr.Cells.Add(newcell("星期天"));
table.Rows.Add(tr);
tr = new TableRow();
int ss = 1;
for (int i = 1; i <= 5; i++)
{
tr.Cells.Add(newcell(string.Format("{0}、{1}节", ss, ss + 1)));
ss = ss + 2;
for (int j = 0; j <= 30; j = j + 5)
{
string name = "t" + pubfunc.NumToStrPrefix0(i + j, 2);
tr.Cells.Add(newcell(CreateTextbox(name,"")));
}
tr.EnableViewState = true;
table.Rows.Add(tr);
tr = new TableRow();
}
tr.EnableViewState = true;
table.Rows.Add(tr);
table.EnableViewState = true;
table.Visible = true;
table.BackColor = System.Drawing.Color.AntiqueWhite;
}
private TableCell newcell(TextBox tb)
{
TableCell tc = new TableCell();
tc.Controls.Add(tb);
tc.Font.Size = FontUnit.Point(10);
tc.VerticalAlign = VerticalAlign.Middle;
return tc;
}
private TableCell newcell(string cellinfo)
{
TableCell tc = new TableCell();
//tc.BackColor = System.Drawing.Color.White;
tc.Text = cellinfo;
tc.VerticalAlign = VerticalAlign.Middle;
return tc;
}
private TextBox CreateTextbox(string ContainerID,string text)
{
string texboxid = string.Format("txt{0}", ContainerID);
TextBox tb = new TextBox();
tb.ID = texboxid;
tb.Text = text;
tb.Width = 50;
tb.Height = 20;
return tb;
}
private void buildIlist(Table table)
{
textlist.Clear();
for (int i = 1; i <= 35; i++)
{
bool flag = false;
foreach (TableRow tr in table.Rows)
{
foreach (TableCell tc in tr.Cells)
{
string id = "txtt" + pubfunc.NumToStrPrefix0(i, 2);
TextBox tb = (TextBox)tc.FindControl(id);
if (tb != null)
{
textlist.Add(tb);
flag = true;
}
if (flag)
break;
}
if (flag)
break;
}
}
}