webform问题?解决100分 我在后台代码中改变了控件的位置,执行DropDownList的SelectedIndexChanged()事件后,控件又回到了原来的位置,而且所有DropDownList绑定的数据都显示不出来了,Page_Load()中的代码已放在if(!IsPostBack){}中了, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我是这样实现控件位置改变的:用两个Panel,定位在表格中,一左一右Pnlleft,Pnlright所有控件起始都放在Pnlleft中,加载页面时通过代码实现将Pnlleft中的部分控件放进Pnlright中Pnlleft.Controls.Remove(控件ID);Pnlright.Controls.Add(控件ID);但是执行DropDownList的SelectedIndexChanged()事件后,又回到初始状态,控件回到Pnlleft中,并且DropDownList绑定的数据都消失了大家帮我想想办法 DropDownList的SelectedIndexChanged()事件就是做关联绑定,但回发后根本就没有绑定初始化放在Page_Load(){}中不行吗?要放在哪里 private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 if(!IsPostBack) { //初始化Panel PanelJudge(); //绑定所有DropDownList DropDownListBind(DDList_dep,"*","tab_department","dep_id","dep_name"); DropDownListBind(DDList_group,"*","tab_group","group_id","group_name"); DropDownListBind(Dropuse_dep,"*","tab_department","dep_id","dep_name"); DropDownListBind(Drop_user,"*","tab_user","user_id","user_name"); Dropindep.Items.Insert(0,new ListItem("-------请选择--------")); DDList_manageclass.Items.Clear(); DDList_manageclass.Items.Insert(0,new ListItem("-------请选择--------")); //根据用户的权限选定“管理分类” GetPurview(); //如果只有一个权限,则锁定该权限 if(DDList_manageclass.Items.Count == 2) { DDList_manageclass.Items[1].Selected = true; DDList_manageclass.Enabled = false; DropBindEqName(); DropBind(Dropeq_spec,"规格",DDList_manageclass); DropBind(Dropeq_class,"类别",DDList_manageclass); DropBind(Droptype,"型号",DDList_manageclass); DropBind(Dropguideline,"主要技术指标",DDList_manageclass); DropBind(Dropuse_place,"使用地点",DDList_manageclass); DropBind(Droptech,"技术状况",DDList_manageclass); DropBind(Dropquality,"质量状况",DDList_manageclass); DropBind(Dropdescription,"简单描述",DDList_manageclass); DropBind(Dropmadein,"制造国",DDList_manageclass); DropBind(Dropfactory,"制造厂",DDList_manageclass); DropBind(Dropbankroll_source,"资金来源",DDList_manageclass); } } }#region 判断Panel /// <summary> /// 根据data.aspx传来的数据,显示相应的项 /// </summary> private void PanelJudge() { bool[] ctrlvisible = new bool[39]; System.Web.UI.WebControls.Panel[] MyPnl = new System.Web.UI.WebControls.Panel[39]; System.Web.UI.WebControls.Panel[] PnlTrue = new System.Web.UI.WebControls.Panel[39]; //初始化数组MyPnl MyPnl[0] = this.Pnluni_number; MyPnl[1] = this.Pnlupper_num; MyPnl[2] = this.Pnldep; MyPnl[3] = this.Pnleq_class; MyPnl[4] = this.Pnlmanageclass; MyPnl[5] = this.Pnluse_dep; MyPnl[6] = this.Pnluser; MyPnl[7] = this.Pnlgroup; MyPnl[8] = this.Pnleqname; MyPnl[9] = this.Pnltype; MyPnl[10] = this.Pnleq_spec; MyPnl[11] = this.Pnlguideline; MyPnl[12] = this.Pnldescription; MyPnl[13] = this.Pnlmadein; MyPnl[14] = this.Pnlfactory; MyPnl[15] = this.Pnlfactory_num; MyPnl[16] = this.Pnlfactory_date; MyPnl[17] = this.Pnldatetime; MyPnl[18] = this.Pnlbankroll_source; MyPnl[19] = this.Pnlvalue; MyPnl[20] = this.Pnlincrease_value; MyPnl[21] = this.Pnldecrease_value; MyPnl[22] = this.Pnlnet_value; MyPnl[23] = this.Pnlcom_coefficient1; MyPnl[24] = this.Pnlcom_coefficient2; MyPnl[25] = this.Pnltech; MyPnl[26] = this.Pnlquality; MyPnl[27] = this.PnlLCdate; MyPnl[28] = this.Pnlcheckup_cyc; MyPnl[29] = this.Pnleffective_date; MyPnl[30] = this.Pnlstkrequi_num; MyPnl[31] = this.Pnlchkaccept_num; MyPnl[32] = this.Pnlchange_causation; MyPnl[33] = this.Pnldeal_advice; MyPnl[34] = this.Pnldeal_price; MyPnl[35] = this.Pnluse_place; MyPnl[36] = this.Pnleq_re; MyPnl[37] = this.Pnlindep; MyPnl[38] = this.Pnlmyfile; ctrlvisible = (bool[])Session["ctrl_v"]; for(int i=0;i<ctrlvisible.Length;i++) { MyPnl[i].Visible = ctrlvisible[i]; } //七个必填项 this.Pnluni_number.Visible = true;//统一编号 this.Pnlmanageclass.Visible = true;//管理分类 this.Pnleqname.Visible = true;//设备名称 this.Pnldep.Visible = true;//归口部门 this.Pnleq_spec.Visible = true;//规格 this.Pnltype.Visible = true;//型号 this.Pnlindep.Visible = true;//是否是独立设备 //将MyPnl中Visible=true的Panel取出放入PnlTrue中 int m; int n=0; for(m=0;m<MyPnl.Length;m++) { if(MyPnl[m].Visible == true && MyPnl[m] != this.Pnleffective_date) { PnlTrue[n] = MyPnl[m]; n++; } } //将显示的Panel放入PnlTrue中,并将第偶数个放入Pnlright,使之分两列显示 for(int x=0;x<PnlTrue.Length;x++) { x++; if(x<PnlTrue.Length && PnlTrue[x] != null) { Pnlright.Controls.Add(PnlTrue[x]); //Pnlleft.Controls.Remove(PnlTrue[x]); } } } #endregion #region 管理分类与设备的属性名关联 /// <summary> /// 管理分类与设备的属性名关联 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DDList_manageclass_SelectedIndexChanged(object sender, System.EventArgs e) { if(DDList_manageclass.SelectedItem.Text == "-------请选择--------") { DropDownListBind(Dropeqname,"*","tab_eqname","eqname_id","eqname_name"); DropBind(Dropeq_spec,"规格"); DropBind(Dropeq_class,"类别"); DropBind(Droptype,"型号"); DropBind(Dropguideline,"主要技术指标"); DropBind(Dropuse_place,"使用地点"); DropBind(Droptech,"技术状况"); DropBind(Dropquality,"质量状况"); DropBind(Dropdescription,"简单描述"); DropBind(Dropmadein,"制造国"); DropBind(Dropfactory,"制造厂"); DropBind(Dropbankroll_source,"资金来源"); } else { DropBindEqName(); DropBind(Dropeq_spec,"规格",DDList_manageclass); DropBind(Dropeq_class,"类别",DDList_manageclass); DropBind(Droptype,"型号",DDList_manageclass); DropBind(Dropguideline,"主要技术指标",DDList_manageclass); DropBind(Dropuse_place,"使用地点",DDList_manageclass); DropBind(Droptech,"技术状况",DDList_manageclass); DropBind(Dropquality,"质量状况",DDList_manageclass); DropBind(Dropdescription,"简单描述",DDList_manageclass); DropBind(Dropmadein,"制造国",DDList_manageclass); DropBind(Dropfactory,"制造厂",DDList_manageclass); DropBind(Dropbankroll_source,"资金来源",DDList_manageclass); } } #endregion 代码乱,请多包涵!其实就是为了实现界面整齐,在代码中动态的将控件位置调整为两列显示,因为要显示的控件的个数是根据用户的选择来确定的,我将每一个控件都放到Panel里,然后根据用户的选择情况显示相应的项,将要显示的Panel装入数组PnlTrue[]中,再按两列显示在界面上。如果在页面上用表格定位的话,位置一死,显示出来的控件会零零散散分布在界面上,不好看我用的方法比较烦,如果你们有更好的方法提供给我,不胜感激! //初始化Panel PanelJudge();放到if(!Page.IsPostBack)外面,使每次加载页面都初始化一次panel 至于你的DropDownList的绑定,我没看懂,抱歉 split和Dataset 关于dbf文件的问题? 如何在c#中post参数给一个php页面 button点第二次才弹出模式窗口 散分200,教你一个散分贴快速结贴方法,JS实现。 高分求数据库条件类 100分跪求各位大老一个.net的安装问题 要在一个子窗体中显示字符,并可以单击选定,该如何实现? C#调用java的webservice需要身份认证 C#:请问关于把一个位图内存对拷到另外一个位图的方法。。 一个初级的二进制文件读写问题 还是数据库,插入关联数据的问题,请大侠指教
用两个Panel,定位在表格中,一左一右Pnlleft,Pnlright
所有控件起始都放在Pnlleft中,加载页面时通过代码实现将Pnlleft中的部分控件放进Pnlright中
Pnlleft.Controls.Remove(控件ID);
Pnlright.Controls.Add(控件ID);
但是执行DropDownList的SelectedIndexChanged()事件后,又回到初始状态,控件回到Pnlleft中,并且DropDownList绑定的数据都消失了
大家帮我想想办法
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
//初始化Panel
PanelJudge(); //绑定所有DropDownList
DropDownListBind(DDList_dep,"*","tab_department","dep_id","dep_name");
DropDownListBind(DDList_group,"*","tab_group","group_id","group_name");
DropDownListBind(Dropuse_dep,"*","tab_department","dep_id","dep_name");
DropDownListBind(Drop_user,"*","tab_user","user_id","user_name"); Dropindep.Items.Insert(0,new ListItem("-------请选择--------"));
DDList_manageclass.Items.Clear();
DDList_manageclass.Items.Insert(0,new ListItem("-------请选择--------")); //根据用户的权限选定“管理分类”
GetPurview();
//如果只有一个权限,则锁定该权限
if(DDList_manageclass.Items.Count == 2)
{
DDList_manageclass.Items[1].Selected = true;
DDList_manageclass.Enabled = false; DropBindEqName();
DropBind(Dropeq_spec,"规格",DDList_manageclass);
DropBind(Dropeq_class,"类别",DDList_manageclass);
DropBind(Droptype,"型号",DDList_manageclass);
DropBind(Dropguideline,"主要技术指标",DDList_manageclass);
DropBind(Dropuse_place,"使用地点",DDList_manageclass);
DropBind(Droptech,"技术状况",DDList_manageclass);
DropBind(Dropquality,"质量状况",DDList_manageclass);
DropBind(Dropdescription,"简单描述",DDList_manageclass);
DropBind(Dropmadein,"制造国",DDList_manageclass);
DropBind(Dropfactory,"制造厂",DDList_manageclass);
DropBind(Dropbankroll_source,"资金来源",DDList_manageclass);
}
}
}#region 判断Panel
/// <summary>
/// 根据data.aspx传来的数据,显示相应的项
/// </summary>
private void PanelJudge()
{
bool[] ctrlvisible = new bool[39];
System.Web.UI.WebControls.Panel[] MyPnl = new System.Web.UI.WebControls.Panel[39];
System.Web.UI.WebControls.Panel[] PnlTrue = new System.Web.UI.WebControls.Panel[39]; //初始化数组MyPnl
MyPnl[0] = this.Pnluni_number;
MyPnl[1] = this.Pnlupper_num;
MyPnl[2] = this.Pnldep;
MyPnl[3] = this.Pnleq_class;
MyPnl[4] = this.Pnlmanageclass;
MyPnl[5] = this.Pnluse_dep;
MyPnl[6] = this.Pnluser;
MyPnl[7] = this.Pnlgroup;
MyPnl[8] = this.Pnleqname;
MyPnl[9] = this.Pnltype;
MyPnl[10] = this.Pnleq_spec;
MyPnl[11] = this.Pnlguideline;
MyPnl[12] = this.Pnldescription;
MyPnl[13] = this.Pnlmadein;
MyPnl[14] = this.Pnlfactory;
MyPnl[15] = this.Pnlfactory_num;
MyPnl[16] = this.Pnlfactory_date;
MyPnl[17] = this.Pnldatetime;
MyPnl[18] = this.Pnlbankroll_source;
MyPnl[19] = this.Pnlvalue;
MyPnl[20] = this.Pnlincrease_value;
MyPnl[21] = this.Pnldecrease_value;
MyPnl[22] = this.Pnlnet_value;
MyPnl[23] = this.Pnlcom_coefficient1;
MyPnl[24] = this.Pnlcom_coefficient2;
MyPnl[25] = this.Pnltech;
MyPnl[26] = this.Pnlquality;
MyPnl[27] = this.PnlLCdate;
MyPnl[28] = this.Pnlcheckup_cyc;
MyPnl[29] = this.Pnleffective_date;
MyPnl[30] = this.Pnlstkrequi_num;
MyPnl[31] = this.Pnlchkaccept_num;
MyPnl[32] = this.Pnlchange_causation;
MyPnl[33] = this.Pnldeal_advice;
MyPnl[34] = this.Pnldeal_price;
MyPnl[35] = this.Pnluse_place;
MyPnl[36] = this.Pnleq_re;
MyPnl[37] = this.Pnlindep;
MyPnl[38] = this.Pnlmyfile; ctrlvisible = (bool[])Session["ctrl_v"]; for(int i=0;i<ctrlvisible.Length;i++)
{
MyPnl[i].Visible = ctrlvisible[i];
} //七个必填项
this.Pnluni_number.Visible = true;//统一编号
this.Pnlmanageclass.Visible = true;//管理分类
this.Pnleqname.Visible = true;//设备名称
this.Pnldep.Visible = true;//归口部门
this.Pnleq_spec.Visible = true;//规格
this.Pnltype.Visible = true;//型号
this.Pnlindep.Visible = true;//是否是独立设备 //将MyPnl中Visible=true的Panel取出放入PnlTrue中
int m;
int n=0;
for(m=0;m<MyPnl.Length;m++)
{
if(MyPnl[m].Visible == true && MyPnl[m] != this.Pnleffective_date)
{
PnlTrue[n] = MyPnl[m];
n++;
}
} //将显示的Panel放入PnlTrue中,并将第偶数个放入Pnlright,使之分两列显示
for(int x=0;x<PnlTrue.Length;x++)
{
x++;
if(x<PnlTrue.Length && PnlTrue[x] != null)
{
Pnlright.Controls.Add(PnlTrue[x]);
//Pnlleft.Controls.Remove(PnlTrue[x]);
}
}
}
#endregion
#region 管理分类与设备的属性名关联
/// <summary>
/// 管理分类与设备的属性名关联
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DDList_manageclass_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(DDList_manageclass.SelectedItem.Text == "-------请选择--------")
{
DropDownListBind(Dropeqname,"*","tab_eqname","eqname_id","eqname_name");
DropBind(Dropeq_spec,"规格");
DropBind(Dropeq_class,"类别");
DropBind(Droptype,"型号");
DropBind(Dropguideline,"主要技术指标");
DropBind(Dropuse_place,"使用地点");
DropBind(Droptech,"技术状况");
DropBind(Dropquality,"质量状况");
DropBind(Dropdescription,"简单描述");
DropBind(Dropmadein,"制造国");
DropBind(Dropfactory,"制造厂");
DropBind(Dropbankroll_source,"资金来源");
}
else
{
DropBindEqName();
DropBind(Dropeq_spec,"规格",DDList_manageclass);
DropBind(Dropeq_class,"类别",DDList_manageclass);
DropBind(Droptype,"型号",DDList_manageclass);
DropBind(Dropguideline,"主要技术指标",DDList_manageclass);
DropBind(Dropuse_place,"使用地点",DDList_manageclass);
DropBind(Droptech,"技术状况",DDList_manageclass);
DropBind(Dropquality,"质量状况",DDList_manageclass);
DropBind(Dropdescription,"简单描述",DDList_manageclass);
DropBind(Dropmadein,"制造国",DDList_manageclass);
DropBind(Dropfactory,"制造厂",DDList_manageclass);
DropBind(Dropbankroll_source,"资金来源",DDList_manageclass);
}
}
#endregion
PanelJudge();放到if(!Page.IsPostBack)外面,使每次加载页面都初始化一次panel