473,800 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

casting of object to retrieve individual value from arraylist

6 New Member
Hi, i am having a problem as im new to c#. I did an arraylist and store my "uid" and want to put it into a row of pictures

pic 1 , pic 2 , pic 3, pic 4

this is my code for putting the "uid" the arraylist

pofile2.aspx.cs
Expand|Select|Wrap|Line Numbers
  1. ArrayList list2 = new ArrayList();
  2. //query to get uid
  3. thesql = "select * from Student where caregroupID= @CareGroupID";
  4.  
  5. using (SqlCommand cmd = new SqlCommand(thesql, con))
  6. {
  7.   cmd.Parameters.AddWithValue("CareGroupID", Session["caregroupID"].ToString());
  8.   con.Open();
  9.  
  10.   using (SqlDataReader reader = cmd.ExecuteReader())
  11.   {
  12.       while (reader.Read())
  13.       {
  14.           list2.Add(reader["uid"].ToString());
  15.       }
  16.   }
  17.   Session["horse"] = list2;
  18.   con.Close();
  19. }
  20.  
I understand my Session becomes an object and so i have to cast it back.
This is my aspx page where i tried to cast it.
Expand|Select|Wrap|Line Numbers
  1. <%ArrayList mylist = (ArrayList)Session["horse"];%> 
  2. <!--fb:fan profile_id="171381255280" name="caregroup" stream="0" connections="8" width="250"></fb:fan-->
  3. </form>
  4. <div>
  5.     <table cellpadding=0 cellspacing=11>
  6.     <tr>
  7.         <%for (int i = 0; i < 8; i++)%>
  8.       <%{ %>
  9.         <td> 
  10.         <fb:profile-pic uid="<%=mylist[i].ToString()%>" facebook-logo="false" width="50" height="50"linked="true" />
  11.         </td>
  12.       <%}%>
  13.     </tr>
  14.     </table>
  15. </div>
  16.  
But it seems like i can't put the cast at my ASPX page. The error states the namespace arraylist does not exist, Any idea what other solution can be used?
Sep 29 '09 #1
13 2779
Plater
7,872 Recognized Expert Expert
Well your error could probably be fixed by saying System.Collecti ons.ArrayList
(or adding the System.Collecti ons namespace for it)

However, if you are interested in display tabluar data in a webpage, I recomend looking up the DataTable object(and the SqlDataAdapter to fill it), then using a GridView object to handle the table building
Sep 29 '09 #2
looper
6 New Member
where do i put the System.Collecti ons.ArrayList
in my ASPX page?
Like <%System.Collec tions.ArrayList ;%>

Sorry Im really new to this
Sep 29 '09 #3
Plater
7,872 Recognized Expert Expert
I would go to the code file, since the exception is probably on the line:
ArrayList list2 = new ArrayList();
And put the cursor over the first ArrayList word. A little red line will probably appear under the last letter. If you move over it, a drop down will appear allowing you to add the namespace if you want?
Sep 29 '09 #4
looper
6 New Member
There is no error in the ArrayList list2 = new ArrayList(); i have all the namespace needed for the code file. But it is in my ASPX page where there is error in <%ArrayList mylist = (ArrayList)Sess ion["horse"];%>.

Hope you guys can understand me.
Sep 29 '09 #5
GaryTexmo
1,501 Recognized Expert Top Contributor
I was under the impression that Platter meant...

Expand|Select|Wrap|Line Numbers
  1. <%System.Collections.ArrayList myList = (System.Collections.ArrayList)Session["horse"];%>
Platter? I've never put C# code on a web page before, so maybe you can't do this...
Sep 29 '09 #6
Plater
7,872 Recognized Expert Expert
Yes Gary that is a valid way of doing it.
I think is a way to do the namespace part in the web page side as well, but i cannot remember the format
Sep 29 '09 #7
GaryTexmo
1,501 Recognized Expert Top Contributor
I did a bit of googling... does this help at all?
http://msdn.microsoft.com/en-us/library/ms164642.aspx

It seems you need to put the namespace references in a web.config file somewhere. This looks like it talks about VB, but I found this same information in relation to C#... so maybe it works like this too?

As I said, I don't know much about this kind of thing, just trying to be helpful. It's definitely confusing... give me a compiler any day! ;)
Sep 29 '09 #8
Plater
7,872 Recognized Expert Expert
Are you positive its on the webpage part and not the code part?
I just threw this line in a page:
<%ArrayList mylist = new ArrayList();%>
And it accepted it just fine, no errors
Sep 29 '09 #9
looper
6 New Member
Thanks guys im able to add <%ArrayList list2 = (ArrayList)Sess ion["horse"];%> right now. It is after i put <add namespace="Syst em.Collections"/> in my webconfig namespace.

But i have another problem now. My list2 in my <fb:profile-pic uid="<%=list2%> "
does not work. Any idea what should i put to get all the uid from the loop?
Expand|Select|Wrap|Line Numbers
  1. <%ArrayList list2 = (ArrayList)Session["horse"];%>
  2. <%for (int i = 0; i < 8; i++)%>
  3.  
  4.               <%{ %>
  5.  
  6.               <td> 
  7.  
  8.               <fb:profile-pic uid="<%=list2%>" facebook-logo="false" width="50" height="50"linked="true" />
  9.               </td>
  10.  
  11.               <%}%>
  12.  
Sep 30 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1146
by: Ken Allen | last post by:
I am contemplating a rather complex inplementation that calls for a factory class that can instantiate a large number of specific business objects, each of which share a set of common base business rules (e.g., Update, Delete, etc.) as well as a set of object specific methods. Of couse, all of the interfaces shall be defined in a common assembly for the client and server components. Since all of these are remoted, presume that the...
2
5481
by: MattC | last post by:
Hi, How can do runtime casting? MyCollection derives from ArrayList I will store lost of different objects that all derive from the same parent class. I then want to be able to pass in the object type and collection type I have a number of classes that derive from ArrayList and have if pick out on ly those i asked for.
3
9696
by: Fred | last post by:
I'm trying to build a hashtable and a arraylist as object value I'm not able to retrieve stored object from the hashtable. Hashtable mp = new Hashtable(); // THE HASHTABLE ArrayList atemp = new ArrayList(); // THE ARRAY StreamWriter sw = new StreamWriter(@"C:\temp\fred.html");
5
2246
by: Stephane | last post by:
Hi, I want to keep a list of my visitors in an ArrayList which I place in the application object like this: Application("Visitors") = new ArrayList(); // The list of visitors Then, each visitors update their own information in that list for every page they visit.
0
1075
by: Jon the Blind | last post by:
I have a set of business object classes built from the typed dataset tool in Visual Studio. Since the individual objects (such as the Order object, for example) inherit from DataRow, a common requirement is to cast an array of DataRows to an array of Orders. But I keep getting InvalidCastExceptions when I do this, for example: Dim orders As Order() = CType(RowsAffected, Order()) In this example, RowsAffected returns an array of...
1
1742
by: Joe | last post by:
Hello All: I am writing a function which accepts an ArrayList as its parameter and converts the contents of the ArrayList into an XmlNodeList. The ArrayList will contain one of several different structures. For example, the structures could be either a Customer structure (which contains a customer id and name) or an Address structure (which contains an address type and street number, city, etc). The XmlNodeList is uded to populate a...
3
1231
by: Andy Chen | last post by:
Hi, I have a Hashtable, key is string and value is ArrayList. The problem is I cannot cast the value from object to ArrayList. like this: Hashtable ht = new Hashtable(); ArrayList al = new ArrayList(); al.Add("test"); ht.Add("key1", al);
5
3012
by: mijobee | last post by:
Hello Everyone, I just wanted to check that I'm using dynamic_cast correctly. I have a hierarchy of objects using pure virtual classes and virtual inheritance to implement interfaces. I ran into a problem using C-style casting to an instance of a derived class from its interface type to a variable of its concrete type. I was confused because I thought C-style casts always compiled even if they wouldn't run correctly at runtime. I...
2
2659
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10275
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.