Click here to Skip to main content
15,898,734 members
Please Sign up or sign in to vote.
3.33/5 (3 votes)
See more:
Hi,

Can anyone help me in casting the base class to Data Collection for an array list

dataServiceColl = new DataServiceCollectiongmcApp>();

GridView1.DataSource = dataServiceColl;

GridView1.EmptyDataText = "No Data Found.";

if (!Page.IsPostBack){

    Uri requestUri = GetQueryRequestUri();

    try  {

        if(authenticationRequired)

            {

service.SendingRequest += new EventHandler<sendingrequesteventargs>(service_SendingRequest);

    }  
 
   logMessage.AppendLine(String.Format("Request uri = '{0}'", requestUri.OriginalString)); 

   var result = service.Execute<gmcapp>(requestUri); 

   dataServiceColl.Load(result);  

  /* Here I am querying the data ,Here I need to type cast */
 
   GridView1.DataSource = dataServiceColl.Select(t => t.prod_desc ="Edibleitem"); 

   logMessage.AppendLine(String.Format("Retrieved '{0}' items", dataServiceColl.Count</gmcapp></sendingrequesteventargs>


Can anyone help me in casting the line i commented in the above code?
Posted
Updated 26-May-11 17:49pm
v5
Comments
Sergey Alexandrovich Kryukov 26-May-11 22:23pm    
Please, format your code yourself, I started but it's crewed up too much.
--SA
HEERAL_MS 26-May-11 22:44pm    
Thx! I formatted it.
Any help appreciated!
Sergey Alexandrovich Kryukov 28-May-11 2:53am    
It's not clear. There is no generic shown. Probably this is typo. Look at "new DataServiceCollectiongmcApp" -- only right angular bracket.

"Casting generic" sounds like oxymoron to me, as generics are designed to avoid type casting.
--SA

I do not quite understand the question. But under Linq you can call .OfType[^] to filter out class based on a specified type.

And then you can rewrite the line to:
C#
// Only select on class ProducClass.
GridView1.DataSource = dataServiceColl.OfType<producclass>().Select(t => t.prod_desc ="EdibleItem");
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 28-May-11 2:57am    
Kim, you had formatting mistakes (you did not replace angular brackets with HTML entities in the generic, so it was mangled. I tried to fix it -- don't you mind? Please check up if it's correct now and fix some more I did not do it right.
Also, please see my comment to OP's question. Still not clear.
--SA
Kim Togo 28-May-11 4:48am    
Hi SA, thanks for fixing up. Yes if forgot to use HTML entities for brackets.
Yes it is,

Problem :

SQL
/* Here I am querying the data ,Here I need to type cast */
   GridView1.DataSource = dataServiceColl.Select(t => t.prod_desc ="Edibleitem");


Solution :

SQL
/* Here I am querying the data ,Here I need to type cast */
   GridView1.DataSource = dataServiceColl.Cast<yourcastingclass>.Select(t => t.prod_desc ="Edibleitem");</yourcastingclass>


It should work.

This may be usefull to you :)

Thanks :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900