473,385 Members | 1,397 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

casting of object to retrieve individual value from arraylist

6
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 2746
Plater
7,872 Expert 4TB
Well your error could probably be fixed by saying System.Collections.ArrayList
(or adding the System.Collections 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
where do i put the System.Collections.ArrayList
in my ASPX page?
Like <%System.Collections.ArrayList ;%>

Sorry Im really new to this
Sep 29 '09 #3
Plater
7,872 Expert 4TB
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
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)Session["horse"];%>.

Hope you guys can understand me.
Sep 29 '09 #5
GaryTexmo
1,501 Expert 1GB
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 Expert 4TB
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 Expert 1GB
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 Expert 4TB
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
Thanks guys im able to add <%ArrayList list2 = (ArrayList)Session["horse"];%> right now. It is after i put <add namespace="System.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
looper
6
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 Expert 4TB
If there are only 6 entries, why would you think doing list2[9] would work?
Sep 30 '09 #12
looper
6
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 Expert 4TB
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
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...
2
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...
3
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...
5
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...
0
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...
1
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...
3
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...
5
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...
2
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);
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.