根据两个或多个条件将数据插入下拉列表。额外空格显示下拉列表中的所有项目由于验证工作而不考虑项目。 如何删除空闲空间。 代码是给定贝娄: -
private void loadUserGroup()
{
CUsers objCUsers=new CUsers();
ddlUserGroup.Items.Clear();
ddlUserGroup.Items.Insert(0, new ListItem("", "0"));
ddlUserGroup.Items.Insert(0, new ListItem("Admin", "2"));
string suseid= User.Identity.Name;
int iUserID = Convert.ToInt32(suseid.ToString());
long iUserParent = objCUsers.SelectUserParent(iUserID);
int iadID=objCUsers.SelectUserIDforAdmin(ddlUserGroup.Items[0].Text);
if(iUserParent==0 || iUserParent==null)
{
ddlUserGroup.Visible = false;
lblUserGroup.Visible = false;
}
else if (iUserParent == iadID)
{
ddlUserGroup.Visible = true;
lblUserGroup.Visible = true;
ddlUserGroup.Items.RemoveAt(0);
ddlUserGroup.Items.Insert(0, new ListItem("Dealer", "4"));
ddlUserGroup.Items.Insert(1, new ListItem("Admin", "3"));//Similar To Admin
}
else
{
long iUserGroup = objCUsers.SelectUserGroup(iUserID);
if(iUserGroup==4)
{
ddlUserGroup.Items.Insert(0, new ListItem("Company", "5"));
}
else if(iUserGroup==3)
{
ddlUserGroup.Items.Insert(0, new ListItem("Admin", "3"));
}
else if (iUserGroup == 5)
{
ddlUserGroup.Items.Insert(0, new ListItem("Company", "5"));
}
}
}
答案 0 :(得分:0)
您必须删除以下行:
ddlUserGroup.Items.Insert(0, new ListItem("", "0")); // blank line
所以新代码如下:
private void loadUserGroup()
{
CUsers objCUsers=new CUsers();
ddlUserGroup.Items.Clear();
//ddlUserGroup.Items.Insert(0, new ListItem("", "0"));
ddlUserGroup.Items.Insert(0, new ListItem("Admin", "2"));
string suseid= User.Identity.Name;
int iUserID = Convert.ToInt32(suseid.ToString());