converting object to string in flex - apache-flex

I've faced a problem converting an Object into String in flex . my object is mydropdown selecteditem and I want to convert it to string and show it on a label tag . I've tried ".toString()" and "as String" and "String()" but none of them worked . anyone has any experience with it ?
thanks

The selectedItem object has data and label properties, depending on the data that you're supplying you'd want something like this:
mydropdown.selectedItem.label

If your "mydropdown selecteditem" is a class that you wrote yourself, you could create a toString() method in there and make it return something useful.

Related

Extending SyndicationItem in VB.net

I need your help for an issue about inheritance.
In a project of mine I am using a the SyndicationFeed .net class to read several feed a make a ul of its elements.
For every element I want to show the feed's image as well, so I wanted to assign the same ImageUrl property of the feed to the single item.
So I started by creating a derived class:
Public Class SyndicationItemWImage
Inherits SyndicationItem
Private mItemImage As Uri
Public Property ItemImage As Uri
Get
Return mItemImage
End Get
Set(value As Uri)
mItemImage = value
End Set
End Property
End Class
Then I would initialize the object and populate it
Dim BlogsPostsWImage As List(Of SyndicationItemWImage)
BlogsPostsWImage = New List(Of SyndicationItemWImage)
…
[initialize SyndFeed]
…
BlogsPostsWImage.AddRange(SyndFeed.Items.ToList.GetRange(0, 10))
Where SynFeed is a well working SyndicationFeed object.
Unfortunately I get an error that the cast is invalid:
System.InvalidCastException: Unable to cast object of type 'System.Collections.Generic.List1[System.ServiceModel.Syndication.SyndicationItem]' to type 'System.Collections.Generic.IEnumerable1[lucamauricom.SyndicationItemWImage]'. at lucamauricom._default.Page_Load(Object sender, EventArgs e)
I do not understand why: shouldn't the cast from a parent class to a child one be allowed?
I think I am missing something fundamental here… not sure what.
Thanks for any help you can provide.
Unfortunately nobody appears to be able to help me with this, so I went on attacking the problem from another angle: I now have an alternative method to accomplish the same goal. I am answering my own question here to document it.
Starting from the same SynFeed as above, I filled a temporary List and then I added an ElementExtension:
Dim TempItems As New List(Of SyndicationItem)
If SyndFeed.Items.Count >= CurrentFeed.TotalElements Then
TempItems.AddRange(SyndFeed.Items.ToList.GetRange(0, CurrentFeed.TotalElements))
Else
TempItems.AddRange(SyndFeed.Items.ToList)
End If
For Each CurrItem As SyndicationItem In TempItems
CurrItem.ElementExtensions.Add("favico", "", SingleFeed.Descendants("//bits.wikimedia.org/favicon/wikipedia.ico")
Next
FeedItems.AddRange(TempItems)
The ElementExtension is called favico, it contains no namespace and has value //bits.wikimedia.org/favicon/wikipedia.ico.
This way, I added the data as a sort of "custom field" that can be easily read on the ASPX page like this:
<img src='<%#CType(Container.DataItem, SyndicationItem).ElementExtensions.ReadElementExtensions(Of String)("favico", "").Item(0).ToString%>' height="16" />
I still cannot figure out what is wrong with the derived class of my original idea, but this second way of dealing with the issue is probably better within the context of Syndication class.

Renaming a button from a string

I am trying to rename a button from a string. Sounds simple enough? Well I have scowered the internet and tried many things however I keep coming up with the same errors.
I have 2 forms and one class file. I am using object orientation to pass a string from a textbox to form1 where upon the "button1.Text" can be change passing it through my "Reference class" (I don't think it can be done any other way)
private void button1_Click_1(object sender, EventArgs e)
{
Refclass Ref = new Refclass();
String but1 = Ref.but1;
String btn = "button1"; this.Controls[btn].Text = but1;
}
I am sure this is probably wrong but I hope by this might be able to understand what I am trying to do. I am calling a string from the "Ref" class and calling the string "hell"
Needless to say I am either getting a debugging error and totally crashing visual studio or I get an error saying "Object reference not set to an instance of an object."
I know I am going wrong somewhere does anyone know where? Thank you.
there is no need of create the object for class.if your class in same assembly.just call like this.
button1.text=ref.but1;
where but1 is a const string in that class.

getting XMLNode attribute's values

I am working on asp.net application. I have a function like this:
Public Function ExtractText(node As XmlNode) As String
End Function
I need to pass following XML as input to above function:
<myrequirements Id="7743" Type="tcg_Concept20_sc_323256419566173_context" StartNode="2724" EndNode="2869">
</myrequirements>
Then I need to get StartNode and EndNode attributes values.
Do I need to use XPath. Please suggest.
Regards,
Asif
You could try using node.Attributes("StartNode").Value and node.Attributes("EndNode").Value which will give you the values of those 2 attributes assuming the XmlNode instance passed as argument contains the XML node shown in your question.

How to access to Object property When the propety I want to access to it's in a String variable

It's too complicate to explain but I'll give you an example
I have an AS3 ResultEvent Object
and this object has several propeties which can be accessed by this like:
event.result.name or event.result.age .....
and, I have this String variable: eventProperty:String that contains "name" or "age"
How do I access to event.result. with the variable?
thank you.
The ActionScript (or ECMAScript) . operator is just syntactic sugar, useful but not really needed. For what you want to do you can use the normal object property access operator [].
So you have to do it like this event.result[ eventProperty ].
Good luck,
Alin
You should probably move your ResultEvent object into an actual Object type first. Then you can access the properties via the object. If your object is an arraycollection, make sure to immediately pass the ResultEvent into an arraycollection since you cannot cast it as you normally might (ArrayCollection)ResultEvent. Here is how to throw the result into an object:
var yourObjectName:Object = event.result;
and here is how to throw it into an arraycollection if you need to:
var yourArrayCollection:ArrayCollection = event.result as ArrayCollection;

Populate ParameterCollection w/ sp_columns (or INFORMATION_SCHEMA.Columns) Results

I'd like to build a ParameterCollection object based on the results of either execute sp_columns MyTableName or SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = 'MyTableName'.
The problem I'm having is assigning the appropriate data type to each Parameter ... I'm unsure of how to gather that information from either of the above two queries and convert it into a System.Data.DbType or System.TypeCode.
Any help is greatly appreciated.
Links: MSDN: sp_columns, MSDN: Information Schema.Columns
Edit: I guess what I'm looking for is functionality similar to Type.GetType("TypeName") that would accept a SQL data type. For example, DbType.GetType("int") or DbType.GetType("varchar").
Edit: Links from Answer: MSDN: Enum.Parse Method
It's actually really easy to do :-) SqlDbType is an enum, and there's a nice static function on the Enum class which accomplishes just what your looking for:
private SqlDbType ConvertType(string typeName)
{
return (SqlDbType)Enum.Parse(typeof(SqlDbType), typeName, true);
}
With this, you should have no trouble converting the output from your INFORMATION_SCHEMA query into a collection of SqlParameters.

Resources