problem understanding the code ---

Last post 08-23-2008 4:03 AM by anonymouswrites. 3 replies.

Sort Posts:

  • problem understanding the code ---

    08-22-2008, 11:32 AM
    • Member
      66 point Member
    • krish3kiran
    • Member since 06-13-2008, 12:27 PM
    • Posts 92
     I  am not able to understand what is happening in this code below. You can see the complete code after this code particularly after populating and binding to the dropdownlist.if (Profile.JobSeeker.ResumeID != -1)

    {

    ListItem li;

    li = ddlCountry.Items.FindByValue(r.CountryID.ToString());

    if (li != null)

    {

    ddlCountry.ClearSelection();

    li.Selected =
    true;

    }

    li = ddlRelocationCountry.Items.FindByValue(r.RelocationCountryID.ToString());

    if (li != null)

    {

    ddlRelocationCountry.ClearSelection();

    li.Selected =
    true;

    }

    }

    -----------------------------------------------------------Complete code-------------

     

    private void FillCountries()

    {

    ddlCountry.DataSource =
    Country.GetCountries();

    ddlCountry.DataTextField = "CountryName";

    ddlCountry.DataValueField = "CountryID";

    ddlCountry.DataBind();

    ddlRelocationCountry.DataSource =
    Country.GetCountries();

    ddlRelocationCountry.DataTextField = "CountryName";

    ddlRelocationCountry.DataValueField = "CountryID";

    ddlRelocationCountry.DataBind();

    if (Profile.JobSeeker.ResumeID != -1)      

    {

    ListItem li;

    li = ddlCountry.Items.FindByValue(r.CountryID.ToString());

    if (li != null)

    {

    ddlCountry.ClearSelection();

    li.Selected =
    true;

    }

    li = ddlRelocationCountry.Items.FindByValue(r.RelocationCountryID.ToString());

    if (li != null)

    {

    ddlRelocationCountry.ClearSelection();

    li.Selected =
    true;

    }

    }

    }

  • Re: problem understanding the code ---

    08-22-2008, 12:08 PM
    Answer

    (Profile.JobSeeker.ResumeID != -1) // if resumeID is not null

    {

    ListItem li;

    li = ddlCountry.Items.FindByValue(r.CountryID.ToString()); // find the item in the dropdowm list based on the r.CountryID;

    if (li != null) // if the item is found.

    {

    ddlCountry.ClearSelection(); // remove the selected item from the dropdown

    li.Selected =
    true; // mark the item found as the selected Item in drop down

    }

    //suppose China was selected country in the dropdown you clear and Italy was the countryId of the item so it will make Italy as selected.

    //Same code is for this 2nd condition.

    li = ddlRelocationCountry.Items.FindByValue(r.RelocationCountryID.ToString());

    if (li != null)

    {

    ddlRelocationCountry.ClearSelection();

    li.Selected =
    true;

    }

    }

     

    hope this helps.

  • Re: problem understanding the code ---

    08-22-2008, 1:01 PM
    • Member
      66 point Member
    • krish3kiran
    • Member since 06-13-2008, 12:27 PM
    • Posts 92

    Thanks but I didn't get u from this statment . what it means ? what is Item here?

  • Re: problem understanding the code ---

    08-23-2008, 4:03 AM
    Answer

    If you bind a dropdown to a list of countries. Each value in the list of countries is rendered as an list item. If you look at the mark up of a drodown it will be

    <asp:DropDownList ID="ddlCountries" runat="server">

       <ListItem>Country 1</ListItem>

       <ListItem>Country 2</ListItem>

       <ListItem>Country 3</ListItem>

     </asp: DropDownList>

     

    Hope now you got the concept of the item.

Page 1 of 1 (4 items)