473,813 Members | 2,579 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
13 2780
looper
6 New Member
Hi again, i did another alternative
Expand|Select|Wrap|Line Numbers
  1. <%ArrayList list2 = (ArrayList)Session["horse"];%> 
  2. <table cellpadding=0 cellspacing=11>
  3. <tr>
  4.               <td> 
  5.               <fb:profile-pic uid="<%=list2[0]%>" facebook-logo="true" width="50" height="50"linked="true" />
  6.               </td>
  7.               <td> 
  8.               <fb:profile-pic uid="<%=list2[1]%>" facebook-logo="true" width="50" height="50"linked="true" />
  9.               </td>
  10.               <td> 
  11.               <fb:profile-pic uid="<%=list2[2]%>" facebook-logo="true" width="50" height="50"linked="true" />
  12.               </td>
  13.               <td> 
  14.               <fb:profile-pic uid="<%=list2[3]%>" facebook-logo="true" width="50" height="50"linked="true" />
  15.               </td>
  16.               <td> 
  17.               <fb:profile-pic uid="<%=list2[4]%>" facebook-logo="true" width="50" height="50"linked="true" />
  18.               </td>
  19.  
  20. </tr>
  21. <tr>
  22.               <td> 
  23.               <fb:profile-pic uid="<%=list2[5]%>" facebook-logo="true" width="50" height="50"linked="true" />
  24.               </td>
  25.               <td> 
  26.               <fb:profile-pic uid="<%=list2[6]%>" facebook-logo="true" width="50" height="50"linked="true" />
  27.               </td>
  28.               <td> 
  29.               <fb:profile-pic uid="<%=list2[7]%>" facebook-logo="true" width="50" height="50"linked="true" />
  30.               </td>
  31.               <td> 
  32.               <fb:profile-pic uid="<%=list2[8]%>" facebook-logo="true" width="50" height="50"linked="true" />
  33.               </td>
  34.               <td> 
  35.               <fb:profile-pic uid="<%=list2[9]%>" facebook-logo="true" width="50" height="50"linked="true" />
  36.               </td>
  37.  
  38. </tr>
  39. </table>
  40.  
But it has an error saying Index was out of range. Must be non-negative and less than the size of the collection. I know in my sql there are only 6 uid, How do i make the array or arraylist size unlimited?
Sep 30 '09 #11
Plater
7,872 Recognized Expert Expert
If there are only 6 entries, why would you think doing list2[9] would work?
Sep 30 '09 #12
looper
6 New Member
Yea! i did it!
Now it works
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. </form> 
  4. <div> 
  5.     <table cellpadding=0 cellspacing=11> 
  6.     <tr> 
  7. <%ArrayList mylist = (ArrayList)Session["horse"];%>  
  8.         <%for (int i = 0; i < list2.Count; i++)%> 
  9.       <%{ %> 
  10.         <td>  
  11.         <fb:profile-pic uid="<%=mylist[i]>" facebook-logo="false" width="50" height="50"linked="true" /> 
  12.         </td> 
  13.       <%}%> 
  14.     </tr> 
  15.     </table> 
  16. </div> 
  17.  
  18.  
  19.  
haha, but it gives me one row only does anyone know how to split my pic

like

pic 1, pic 2, pic 3
pic 4, pic 5, pic 6
Sep 30 '09 #13
Plater
7,872 Recognized Expert Expert
Just start doing the math out?
Sep 30 '09 #14

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
1232
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
2662
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
9734
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
9607
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10407
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
10422
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
9222
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
6897
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
5705
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4358
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
3885
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.