Retrieve SortedList from Class (App_Code)

S

sck10

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
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 
S

sck10

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...
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 
S

sck10

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top