Retrieve SortedList from Class (App_Code)

Discussion in 'ASP .Net' started by sck10, Sep 24, 2006.

  1. sck10

    sck10 Guest

    Hello,

    I have a method in my codefile that builds a sorted list (see CodeFile). I
    am trying to create a class that does the same thing (see App_Code).

    CodeFile
    ===================================
    public void PostSearch(string HRID)
    {
    SortedList PostSearchList = new SortedList();

    try
    {

    ....

    foreach(PropertyValueCollection props in item.Properties)
    {
    PostSearchList.Add(props.PropertyName.ToString(),
    props[0].ToString());
    }

    //Set Values
    this.hdnLDAPEmail.Value = PostSearchList["mail"].ToString().Trim();
    this.hdnLDAPTelephone.Value =
    PostSearchList["telephonenumber"].ToString().Trim();
    } // end try

    catch(Exception ex)
    {
    string strNoLDAP = "<br /><br />Please submit a <a
    href='members.aspx'>New HRID</a>.<br />";
    }
    }



    App_Code
    ===================================
    public SortedList PostSearchHRID(string HRID)
    {
    SortedList PostSearchList = new SortedList();

    try
    {
    foreach(PropertyValueCollection props in item.Properties)
    {
    PostSearchList.Add(props.PropertyName.ToString(),
    props[0].ToString());
    }

    return PostSearchList;

    } // end try

    catch(Exception ex)
    {
    strNoLDAP += "<br /><br /><span class=BlkB>LDAP Error</span><br />" +
    ex.Message.ToString();

    PostSearchList.Add("Catch Exception", strNoLDAP);

    return PostSearchList;
    }
    } // end class



    My question is how do you return a sorted list that's in the class?

    Code calling the class
    ======================
    protected void Page_Load(object sender, EventArgs e)
    {
    string LDAPName = this.AppCodePostSearch("cn").ToString();
    }

    protected SortedList AppCodePostSearch()
    {
    PostSearch PostSearchHelper = new PostSearch();
    return PostSearchHelper.PostSearchHRID(this.txtHRID.Text);
    }


    When I try to reference the class, I get the following:

    ?LDAPName = "System.Collections.SortedList"

    The actual value should be ?LDAPName = "Last Name, First Name"


    Any help would be appreciated. Thanks, sck10
    sck10, Sep 24, 2006
    #1
    1. Advertising

  2. Hi sck10,

    Do you have another implementation of AppCodePostSearch() which takes one
    string parameter? I think your code calling the AppCodePostSearch() should
    be:

    protected void Page_Load(object sender, EventArgs e)
    {
    string LDAPName = this.AppCodePostSearch()["cn"].ToString();
    }

    Sincerely,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications. If you are using Outlook Express, please make sure you clear the
    check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
    promptly.

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Sep 25, 2006
    #2
    1. Advertising

  3. sck10

    sck10 Guest

    Thank you very much Walter,

    That answered my second question of how to send a value to the method
    "AppCodePostSearch(this.HRID.Text)":

    string LDAPName = this.AppCodePostSearch(this.HRID.Text)["cn"].ToString();

    Cheers...



    "Walter Wang [MSFT]" <> wrote in message
    news:p...
    > Hi sck10,
    >
    > Do you have another implementation of AppCodePostSearch() which takes one
    > string parameter? I think your code calling the AppCodePostSearch() should
    > be:
    >
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > string LDAPName = this.AppCodePostSearch()["cn"].ToString();
    > }
    >
    > Sincerely,
    > Walter Wang (, remove 'online.')
    > Microsoft Online Community Support
    >
    > ==================================================
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    > ications. If you are using Outlook Express, please make sure you clear the
    > check box "Tools/Options/Read: Get 300 headers at a time" to see your
    > reply
    > promptly.
    >
    > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 1 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions or complex
    > project analysis and dump analysis issues. Issues of this nature are best
    > handled working with a dedicated Microsoft Support Engineer by contacting
    > Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/subscriptions/support/default.aspx.
    > ==================================================
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >
    sck10, Sep 25, 2006
    #3
  4. Hi sck10,

    Sorry, I overlooked the first question "how do you return a sorted list
    that's in the class?". However, I'm not very clear about what do you mean
    of the question. Could you please depict more? Thanks.

    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Sep 26, 2006
    #4
  5. sck10

    sck10 Guest

    Hi Walter,

    Both my question of 1. how to return a SortedList and how to provide a value
    to the method were answered when you showed me the correct syntax.

    I originally created the following to call a class in App_Code that I could
    supply a parameter value:

    Example 1
    ========================
    protected SortedList AppCodePostSearch(string HRID)
    {
    PostSearch PostSearchHelper = new PostSearch();
    return PostSearchHelper.PostSearchHRID(HRID);
    }

    I couldn't figure out how to send a value to the class so I hard coded the
    method:

    Example 2
    ========================
    protected SortedList AppCodePostSearch()
    {
    PostSearch PostSearchHelper = new PostSearch();
    return PostSearchHelper.PostSearchHRID(this.txtHRID.Text);
    }


    The reason I couldn't figure out how to send the parameter value (example 1)
    instead of hard coding the value (example 2) was because my of my syntax:

    What I originally had was wrong:
    string LDAPName = this.AppCodePostSearch["cn"].ToString();

    which should have been:
    string LDAPName = this.AppCodePostSearch().["cn"].ToString();

    which leads to:
    string LDAPName = this.AppCodePostSearch(this.HRID.Text)["cn"].ToString();

    As always, thanks for all your help...

    sck10




    "Walter Wang [MSFT]" <> wrote in message
    news:...
    > Hi sck10,
    >
    > Sorry, I overlooked the first question "how do you return a sorted list
    > that's in the class?". However, I'm not very clear about what do you mean
    > of the question. Could you please depict more? Thanks.
    >
    > Regards,
    > Walter Wang (, remove 'online.')
    > Microsoft Online Community Support
    >
    > ==================================================
    > When responding to posts, please "Reply to Group" via your newsreader so
    > that others may learn and benefit from your issue.
    > ==================================================
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >
    sck10, Sep 26, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan Sokalski

    Problem with SortedList

    Nathan Sokalski, May 30, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,864
    Karl Seguin
    May 30, 2005
  2. Thomas Weidenfeller

    Re: SortedList ?

    Thomas Weidenfeller, Jul 1, 2003, in forum: Java
    Replies:
    3
    Views:
    2,852
    Tim Tyler
    Jul 10, 2003
  3. Phil Hanna

    Re: SortedList ?

    Phil Hanna, Jul 2, 2003, in forum: Java
    Replies:
    0
    Views:
    810
    Phil Hanna
    Jul 2, 2003
  4. B-rad the Beat Nick

    SortedList: best practices with java 1.5

    B-rad the Beat Nick, Nov 4, 2005, in forum: Java
    Replies:
    5
    Views:
    113,007
    Roedy Green
    Nov 5, 2005
  5. jc
    Replies:
    1
    Views:
    697
    sloan
    Jul 15, 2008
Loading...

Share This Page