Home > DeveloperSection > Forums > Free Space in DropdownList
Jayden Bell
Jayden Bell

Total Post:105

Points:739
Posted on    April-10-2014 11:45 PM

 C# C# 
Ratings:


 1 Reply(s)
 1088  View(s)
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"));

        }      

    }  

}



Pravesh Singh

Total Post:411

Points:2881
Posted on    April-11-2014 12:09 AM

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

}


Don't want to miss updates? Please click the below button!

Follow MindStick