问题描述
private void rightsload()
{
DataSet EmpDs = new DataSet();
EmpDs =(DataSet)Session [EmpId ];
DataRow dr = EmpDs.Tables [0] .NewRow();
dr [EmpName] =全部;
dr [EmpId] = 0;
EmpDs.Tables [0] .Rows.InsertAt(dr,0);
if(EmpDs.Tables [0] .Rows.Count> 0)
{
DataView view = new DataView(EmpDs。 Tables [0],null,EmpId,DataViewRowState.CurrentRows);
ddlEmp.DataTextField =EmpName;
ddlEmp.DataValueField =EmpId;
ddlEmp.DataSource = view;
ddlEmp.DataBind();
}
}
每次回发都会全部倍增,从而导致页面回发
private void rightsload()
{
DataSet EmpDs = new DataSet();
EmpDs = (DataSet)Session["EmpId"];
DataRow dr = EmpDs.Tables[0].NewRow();
dr["EmpName"] = "All";
dr["EmpId"] = 0;
EmpDs.Tables[0].Rows.InsertAt(dr, 0);
if (EmpDs.Tables[0].Rows.Count > 0)
{
DataView view = new DataView(EmpDs.Tables[0], null, "EmpId", DataViewRowState.CurrentRows);
ddlEmp.DataTextField = "EmpName";
ddlEmp.DataValueField = "EmpId";
ddlEmp.DataSource = view;
ddlEmp.DataBind();
}
}
The "All" multiplies during each postback and thus leads to postback of page too
推荐答案
这篇关于如何使用值成员和数据成员从数据库填充控件时,如何防止下拉列表中出现重复值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!