在Panel中动态创建的控件 但是读取Panel中的Controls=1 创建的时候又不是正确的。代码如下:namespace SHYX.WebUI.Bussiness
{
public partial class DBCEdt : SHYX.WebUI.PageBase
{ protected void Page_Load(object sender, EventArgs e)
{
CheckRight(Constants.BUSINESSUNIT_GGSQSHList_MODULEID);
string opt = Request.Params.Get("Opt");
Session["DBCList:Opt"] = opt;
this.tbYwlx.Text = "分析调查";
Session["DBCEdt:ZBID"] = Request.Params.Get("ZBID");
string ZMDBM = Request.Params.Get("ZMDBM");
if (!Page.IsPostBack)
{
if (opt != null)
Opt = opt;
if (Opt == "0")
{
this.tbZT.Text = "";
}
else
{
SetCtrols(true);
this.tbZT.Text = "新调查";
}
if (Opt != "1")
{
DCBMFacade facade = new DCBMFacade();
DCBM dCBM = facade.GetDCBM(ZBID);
LoadData(dCBM);
XSDCMQ(ZBID);
}
}
} protected void XSDCMQ(int ZBID)
{
DCBDFacade facede = new DCBDFacade();
IList<DCBD> List = facede.GetDCBDs(ZBID);
string BeginName = "";
string EndName = "";
int XH = 1;
this.ph1.Controls.Clear();
foreach (DCBD dCBD in List)
{
BeginName = dCBD.DLMC.ToString();
if (BeginName != EndName)
{
XH = 1;
Control c = new Control();
c = ParseControl("<hr>");
this.ph1.Controls.Add(c);
c = ParseControl(" <asp:Label ID='Label1' runat='server' Text=" + dCBD.DLMC.ToString() + "></asp:Label><br/>");
this.ph1.Controls.Add(c);
c = ParseControl("<hr>");
this.ph1.Controls.Add(c);
if (dCBD.LB == 1)
{ string Sr1 = " <br/> <asp:Label ID='Label2' runat='server' Text=" + XH.ToString() + "、></asp:Label> ";
c = ParseControl(Sr1);
this.ph1.Controls.Add(c); Label lb = new Label();
lb.Width = 200;
lb.Text = dCBD.XMMC.ToString();
lb.ID = dCBD.MXID.ToString() + "/1";
ph1.Controls.Add(lb);
DropDownList DDL = new DropDownList();
DDL.ID = dCBD.MXID.ToString();
DCBMFacade facade1 = new DCBMFacade();
IList<DCBM> List1 = facade1.GetDCBDXL(int.Parse(dCBD.XMID.ToString()));
foreach (DCBM dCBM in List1)
{
DDL.Items.Add(dCBM.NR);
}
DDL.Text = dCBD.XMNR.ToString();
DDL.Width = 150;
ph1.Controls.Add(DDL);
if (dCBD.BT == 1)
{
Label lb1 = new Label();
lb1.Text = "必填";
lb1.Style["color"] = "red";
lb1.ID = dCBD.MXID.ToString() + "/2";
ph1.Controls.Add(lb1);
} }
else
{
string Sr = "<br/> <asp:Label ID='Label3' runat='server' Text=" + XH.ToString() + "、></asp:Label> ";
c = ParseControl(Sr);
this.ph1.Controls.Add(c); Label lb = new Label();
lb.Width = 200;
lb.Text = dCBD.XMMC.ToString();
lb.ID = dCBD.MXID.ToString() + "/1";
ph1.Controls.Add(lb);
TextBox tb = new TextBox();
tb.ID = dCBD.MXID.ToString();
tb.Width = 150;
tb.Text = dCBD.XMNR.ToString();
ph1.Controls.Add(tb); if (dCBD.BT == 1)
{
Label lb1 = new Label();
lb1.Text = "必填";
lb1.Style["color"] = "red";
lb1.ID = dCBD.MXID.ToString() + "/2";
ph1.Controls.Add(lb1);
}
} BeginName = dCBD.DLMC; }
else
{
XH = XH + 1;
Control c = new Control();
if (dCBD.LB == 1)
{ string Sr1 = " <br/> <asp:Label ID='Label4' runat='server' Text=" + XH.ToString() + "、></asp:Label> ";
c = ParseControl(Sr1);
this.ph1.Controls.Add(c); Label lb = new Label();
lb.Width = 200;
lb.Text = dCBD.XMMC.ToString();
lb.ID = dCBD.MXID.ToString() + "/1";
ph1.Controls.Add(lb);
DropDownList DDL = new DropDownList();
DDL.ID = dCBD.MXID.ToString();
DCBMFacade facade1 = new DCBMFacade();
IList<DCBM> List1 = facade1.GetDCBDXL(int.Parse(dCBD.XMID.ToString()));
foreach (DCBM dCBM in List1)
{
DDL.Items.Add(dCBM.NR);
}
DDL.Width = 150;
DDL.Text = dCBD.XMNR.ToString();
ph1.Controls.Add(DDL);
if (dCBD.BT == 1)
{
Label lb1 = new Label();
lb1.Text = "必填";
lb1.Style["color"] = "red";
lb1.ID = dCBD.MXID.ToString() + "/2";
ph1.Controls.Add(lb1);
}
}
else
{
string Sr = "<br/> <asp:Label ID='Label5' runat='server' Text=" + XH.ToString() + "、></asp:Label> ";
c = ParseControl(Sr);
this.ph1.Controls.Add(c); Label lb = new Label();
lb.Width = 200;
lb.Text = dCBD.XMMC.ToString();
lb.ID = dCBD.MXID.ToString() + "/1";
ph1.Controls.Add(lb);
TextBox tb = new TextBox();
tb.ID = dCBD.MXID.ToString();
tb.Width = 150;
tb.Text = dCBD.XMNR.ToString();
ph1.Controls.Add(tb); if (dCBD.BT == 1)
{
Label lb1 = new Label();
lb1.Text = "必填";
lb1.Style["color"] = "red";
lb1.ID = dCBD.MXID.ToString() + "/2";
ph1.Controls.Add(lb1);
} } BeginName = dCBD.DLMC; }
EndName = dCBD.DLMC;
}
int ii = this.ph1.Controls.Count; }
private void findcontrol()
{
string Err = "";
foreach (Control c in this.ph1.Controls)
{
// if (c is Panel) findcontrol(c); //递归
if (c is TextBox)
{
string MXID = (c as TextBox).ID;
string Text = (c as TextBox).Text; //直接访问textbox组件
DCBDFacade facadeD = new DCBDFacade();
Err = facadeD.UpdateDCBD(int.Parse(MXID), Text, "");
if (Err != "")
{
ShowMessage("提交失败!");
break;
}
}
if (c is DropDownList)
{
string MXID = (c as DropDownList).ID;
string Text = (c as DropDownList).Text;
DCBDFacade facadeD = new DCBDFacade();
Err = facadeD.UpdateDCBD(int.Parse(MXID), Text, "");
if (Err != "")
{
ShowMessage("提交失败!");
break;
}
}
}
}
protected void MyButton_Click(object sender, EventArgs e)
{
findcontrol();
}
}
}
{
public partial class DBCEdt : SHYX.WebUI.PageBase
{ protected void Page_Load(object sender, EventArgs e)
{
CheckRight(Constants.BUSINESSUNIT_GGSQSHList_MODULEID);
string opt = Request.Params.Get("Opt");
Session["DBCList:Opt"] = opt;
this.tbYwlx.Text = "分析调查";
Session["DBCEdt:ZBID"] = Request.Params.Get("ZBID");
string ZMDBM = Request.Params.Get("ZMDBM");
if (!Page.IsPostBack)
{
if (opt != null)
Opt = opt;
if (Opt == "0")
{
this.tbZT.Text = "";
}
else
{
SetCtrols(true);
this.tbZT.Text = "新调查";
}
if (Opt != "1")
{
DCBMFacade facade = new DCBMFacade();
DCBM dCBM = facade.GetDCBM(ZBID);
LoadData(dCBM);
XSDCMQ(ZBID);
}
}
} protected void XSDCMQ(int ZBID)
{
DCBDFacade facede = new DCBDFacade();
IList<DCBD> List = facede.GetDCBDs(ZBID);
string BeginName = "";
string EndName = "";
int XH = 1;
this.ph1.Controls.Clear();
foreach (DCBD dCBD in List)
{
BeginName = dCBD.DLMC.ToString();
if (BeginName != EndName)
{
XH = 1;
Control c = new Control();
c = ParseControl("<hr>");
this.ph1.Controls.Add(c);
c = ParseControl(" <asp:Label ID='Label1' runat='server' Text=" + dCBD.DLMC.ToString() + "></asp:Label><br/>");
this.ph1.Controls.Add(c);
c = ParseControl("<hr>");
this.ph1.Controls.Add(c);
if (dCBD.LB == 1)
{ string Sr1 = " <br/> <asp:Label ID='Label2' runat='server' Text=" + XH.ToString() + "、></asp:Label> ";
c = ParseControl(Sr1);
this.ph1.Controls.Add(c); Label lb = new Label();
lb.Width = 200;
lb.Text = dCBD.XMMC.ToString();
lb.ID = dCBD.MXID.ToString() + "/1";
ph1.Controls.Add(lb);
DropDownList DDL = new DropDownList();
DDL.ID = dCBD.MXID.ToString();
DCBMFacade facade1 = new DCBMFacade();
IList<DCBM> List1 = facade1.GetDCBDXL(int.Parse(dCBD.XMID.ToString()));
foreach (DCBM dCBM in List1)
{
DDL.Items.Add(dCBM.NR);
}
DDL.Text = dCBD.XMNR.ToString();
DDL.Width = 150;
ph1.Controls.Add(DDL);
if (dCBD.BT == 1)
{
Label lb1 = new Label();
lb1.Text = "必填";
lb1.Style["color"] = "red";
lb1.ID = dCBD.MXID.ToString() + "/2";
ph1.Controls.Add(lb1);
} }
else
{
string Sr = "<br/> <asp:Label ID='Label3' runat='server' Text=" + XH.ToString() + "、></asp:Label> ";
c = ParseControl(Sr);
this.ph1.Controls.Add(c); Label lb = new Label();
lb.Width = 200;
lb.Text = dCBD.XMMC.ToString();
lb.ID = dCBD.MXID.ToString() + "/1";
ph1.Controls.Add(lb);
TextBox tb = new TextBox();
tb.ID = dCBD.MXID.ToString();
tb.Width = 150;
tb.Text = dCBD.XMNR.ToString();
ph1.Controls.Add(tb); if (dCBD.BT == 1)
{
Label lb1 = new Label();
lb1.Text = "必填";
lb1.Style["color"] = "red";
lb1.ID = dCBD.MXID.ToString() + "/2";
ph1.Controls.Add(lb1);
}
} BeginName = dCBD.DLMC; }
else
{
XH = XH + 1;
Control c = new Control();
if (dCBD.LB == 1)
{ string Sr1 = " <br/> <asp:Label ID='Label4' runat='server' Text=" + XH.ToString() + "、></asp:Label> ";
c = ParseControl(Sr1);
this.ph1.Controls.Add(c); Label lb = new Label();
lb.Width = 200;
lb.Text = dCBD.XMMC.ToString();
lb.ID = dCBD.MXID.ToString() + "/1";
ph1.Controls.Add(lb);
DropDownList DDL = new DropDownList();
DDL.ID = dCBD.MXID.ToString();
DCBMFacade facade1 = new DCBMFacade();
IList<DCBM> List1 = facade1.GetDCBDXL(int.Parse(dCBD.XMID.ToString()));
foreach (DCBM dCBM in List1)
{
DDL.Items.Add(dCBM.NR);
}
DDL.Width = 150;
DDL.Text = dCBD.XMNR.ToString();
ph1.Controls.Add(DDL);
if (dCBD.BT == 1)
{
Label lb1 = new Label();
lb1.Text = "必填";
lb1.Style["color"] = "red";
lb1.ID = dCBD.MXID.ToString() + "/2";
ph1.Controls.Add(lb1);
}
}
else
{
string Sr = "<br/> <asp:Label ID='Label5' runat='server' Text=" + XH.ToString() + "、></asp:Label> ";
c = ParseControl(Sr);
this.ph1.Controls.Add(c); Label lb = new Label();
lb.Width = 200;
lb.Text = dCBD.XMMC.ToString();
lb.ID = dCBD.MXID.ToString() + "/1";
ph1.Controls.Add(lb);
TextBox tb = new TextBox();
tb.ID = dCBD.MXID.ToString();
tb.Width = 150;
tb.Text = dCBD.XMNR.ToString();
ph1.Controls.Add(tb); if (dCBD.BT == 1)
{
Label lb1 = new Label();
lb1.Text = "必填";
lb1.Style["color"] = "red";
lb1.ID = dCBD.MXID.ToString() + "/2";
ph1.Controls.Add(lb1);
} } BeginName = dCBD.DLMC; }
EndName = dCBD.DLMC;
}
int ii = this.ph1.Controls.Count; }
private void findcontrol()
{
string Err = "";
foreach (Control c in this.ph1.Controls)
{
// if (c is Panel) findcontrol(c); //递归
if (c is TextBox)
{
string MXID = (c as TextBox).ID;
string Text = (c as TextBox).Text; //直接访问textbox组件
DCBDFacade facadeD = new DCBDFacade();
Err = facadeD.UpdateDCBD(int.Parse(MXID), Text, "");
if (Err != "")
{
ShowMessage("提交失败!");
break;
}
}
if (c is DropDownList)
{
string MXID = (c as DropDownList).ID;
string Text = (c as DropDownList).Text;
DCBDFacade facadeD = new DCBDFacade();
Err = facadeD.UpdateDCBD(int.Parse(MXID), Text, "");
if (Err != "")
{
ShowMessage("提交失败!");
break;
}
}
}
}
protected void MyButton_Click(object sender, EventArgs e)
{
findcontrol();
}
}
}
解决方案 »
- 这是什么错误啊 大侠们,将截断字符串或二进制数据。
- 读取大数据的时候,可否用new 新对象来存储数据?
- 亲们,还是昨天那个问题
- C++结构转C#结构遇到尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
- form切換問題
- 如何让 PcitureBox 控件中,图片的某一区示域(坐标系20,20;50,50),当鼠标移上去时,该区域用高亮或其它效果呀?
- 求教DATAGRID的数据同步问题
- ContentType的问题,高分请教
- 是不是用.NET做的数据库软件,一定要连接到服务器上的数据库?
- 未将对象引用设置到对象的实例,怎么解决??
- C#如何创建内存位图
- 关于Visual Studio中窗体的咨询
你应该在Page_Load()中再重新添加一次才可以的
{
CheckRight(Constants.BUSINESSUNIT_GGSQSHList_MODULEID);
string opt = Request.Params.Get("Opt");
Session["DBCList:Opt"] = opt;
this.tbYwlx.Text = "分析调查";
Session["DBCEdt:ZBID"] = Request.Params.Get("ZBID");
string ZMDBM = Request.Params.Get("ZMDBM");
if (!Page.IsPostBack)
{
XSDCMQ(ZBID);//生成控件
}
}还是放在if (!Page.IsPostBack)
{
}
XSDCMQ(ZBID);//生成控件