Free Space in DropdownList

Total Post:110

Points:774

C# 
C#
 1738  View(s)
Ratings:
Rate this:

Inserting Data in Drop Down List Based on two or more conditions .An Extra Space is Display Bellow all Items in Drop down list Which is not consider an item Because of Validation Working. How to remove the free Space?

 The code is Given Bellow:-

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"));
        }      
    }  
}
  1. Re: Free Space in DropdownList

    Hi Jayden,


    You have to remove the following line:

    ddlUserGroup.Items.Insert(0, new ListItem("", "0")); // blank line

    So the new code looks like:

    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());
    }

      Modified On Apr-04-2018 05:16:44 AM

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.