遍历Label 和遍历 DropDownList
作者:admin 日期:2007-12-04
动态增加表字段对数据库稳定性有很大影响,那只好来死的了,嘿嘿。
说明:pnlMaterial是容器名,页面中有Label1-Label40, Dropdownlist1-Dropdownlist40,如此之多控件....
///
/// 遍历页面的label并赋值, ///
protected void RenameLabel()
{
foreach (Control ctr in this.pnlMaterial.Controls)
{
if (ctr.GetType().ToString() == "System.Web.UI.WebControls.Label")
{
//Response.Write("id:" + ctr.ID+ " text:" + ((Label)ctr).Text + "
");
if (ctr.ID.ToString().Length == 6)
{
int LabelId1 = Convert.ToInt32(ctr.ID.Substring(5, 1).ToString().Trim());
((Label)ctr).Text = BLL.EDI.EDIType.GetTypeName(LabelId1);
}
if (ctr.ID.ToString().Length == 7)
{
int LabelId2 = Convert.ToInt32(ctr.ID.Substring(5, 2).ToString().Trim());
((Label)ctr).Text = BLL.EDI.EDIType.GetTypeName(LabelId2);
}
}
}
}
///
/// 遍历dropdownlist赋值
///
protected void SetDropDownListValue()
{
foreach (Control ctr in this.pnlMaterial.Controls)
{
if (ctr.GetType().ToString() == "System.Web.UI.WebControls.DropDownList")
{
//Response.Write("id:" + ctr.ID + " text:" + ((DropDownList)ctr).DataTextField.ToString() + "
");
if (ctr.ID.ToString().Length == 13)
{
int LabelId1 = Convert.ToInt32(ctr.ID.Substring(12, 1).ToString().Trim());
((DropDownList)ctr).DataSource = BLL.EDI.EDIMaterial.List(LabelId1);
((DropDownList)ctr).DataValueField = "mName";
((DropDownList)ctr).DataTextField = "mCode";
((DropDownList)ctr).DataBind();
}
if (ctr.ID.ToString().Length == 14)
{
int LabelId2 = Convert.ToInt32(ctr.ID.Substring(12, 2).ToString().Trim());
((DropDownList)ctr).DataSource = BLL.EDI.EDIMaterial.List(LabelId2);
((DropDownList)ctr).DataValueField = "mName";
((DropDownList)ctr).DataTextField = "mCode";
((DropDownList)ctr).DataBind();
}
}
}
}
说明:pnlMaterial是容器名,页面中有Label1-Label40, Dropdownlist1-Dropdownlist40,如此之多控件....
///
/// 遍历页面的label并赋值, ///
protected void RenameLabel()
{
foreach (Control ctr in this.pnlMaterial.Controls)
{
if (ctr.GetType().ToString() == "System.Web.UI.WebControls.Label")
{
//Response.Write("id:" + ctr.ID+ " text:" + ((Label)ctr).Text + "
");
if (ctr.ID.ToString().Length == 6)
{
int LabelId1 = Convert.ToInt32(ctr.ID.Substring(5, 1).ToString().Trim());
((Label)ctr).Text = BLL.EDI.EDIType.GetTypeName(LabelId1);
}
if (ctr.ID.ToString().Length == 7)
{
int LabelId2 = Convert.ToInt32(ctr.ID.Substring(5, 2).ToString().Trim());
((Label)ctr).Text = BLL.EDI.EDIType.GetTypeName(LabelId2);
}
}
}
}
///
/// 遍历dropdownlist赋值
///
protected void SetDropDownListValue()
{
foreach (Control ctr in this.pnlMaterial.Controls)
{
if (ctr.GetType().ToString() == "System.Web.UI.WebControls.DropDownList")
{
//Response.Write("id:" + ctr.ID + " text:" + ((DropDownList)ctr).DataTextField.ToString() + "
");
if (ctr.ID.ToString().Length == 13)
{
int LabelId1 = Convert.ToInt32(ctr.ID.Substring(12, 1).ToString().Trim());
((DropDownList)ctr).DataSource = BLL.EDI.EDIMaterial.List(LabelId1);
((DropDownList)ctr).DataValueField = "mName";
((DropDownList)ctr).DataTextField = "mCode";
((DropDownList)ctr).DataBind();
}
if (ctr.ID.ToString().Length == 14)
{
int LabelId2 = Convert.ToInt32(ctr.ID.Substring(12, 2).ToString().Trim());
((DropDownList)ctr).DataSource = BLL.EDI.EDIMaterial.List(LabelId2);
((DropDownList)ctr).DataValueField = "mName";
((DropDownList)ctr).DataTextField = "mCode";
((DropDownList)ctr).DataBind();
}
}
}
}
评论: 0 | 引用: 0 | 查看次数: 13007
发表评论