FREE SPACE IN DROPDOWNLIST

Jayden Bell

Total Post:110

Points:774
Posted by  Jayden Bell
C# 
C#
 1337  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. Pravesh Singh

    Post:412

    Points:2888
    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());

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!