I'll explain my problem as brief as possible. I have a variable bandName, the value is String that i get through an API.
public function haalNaam(selectedChart:Object):String
{
var bandName:String = selectedChart.name;
}
I use this var in a repeater for a label. This repeater repeats 5 times, so it shows the 5 most hyped artists:
<repeater>
<label text="{haalNaam(lastfmCollection.currentItem)}"/>
</repeater>
Next, i had to transport the var bandName to another component. I managed to do this with this command:
var theName = "LastFmApi(this.parentApplication).bandName".
This code works, but I only manage to get the bandName of the last element in the repeater (5th one). I have no idea how i can
receive the names of the artists 1,2,3 or 4. How can i get to those values?
First, it doesn't look like what you've pasted in is functional code (your haalName function doesn't return anything, and your repeater doesn't have the id referred to in the label).
Second, why don't you just use lastfmCollection.currentItem.name in the label's text property, and skip the function call?
Third, you don't say exactly what the goal is, so I'll assume that you want to click one of the items in the repeater and put the label text in the variable theName. That would look like this:
theName=(event.target as Label).text;
Note that you may also want to consider using a DataGroup.
Related
I am using datagrid with inline editor which have validatebox, numberbox, and combobox. What I am try to do is when I select the combobox, I need to set numberbox prefix as currency symbol as I want. If I want to set the value to the numberbox, usually write like this:
var ed8 = $("#dg").datagrid("getEditor", {index:idx, field:'cost'});
$(ed8.target).numberbox('setValue',value);
but I am stack on case how to change/set the property "prefix" of numberbox.
One more thing that I want to ask, Is that possible to set multiple prefix in one field (one row one prefix) of datagrid?
I just found the solution by put the code like this.
var ed8 = $("#dg").datagrid("getEditor", {index:idx, field:'cost'});
var opts = $(ed8.target).numberbox('options');
opts.prefix = '$';
It is possible to set multiple prefix on a field
hope this can help others.
I am trying to create a poll system that will ask the users for the number of options they would like to add from a dropdownlist.
Then when the user choose a number i would like to add text-boxes for those numbers and finally use asp.net to iterate through the text-boxes and add their values in the database.
Example:
User chooses to add 5 options.
I use Jquery to to append 5 inputs to the form.
User adds their values.
I iterate through the text-boxes and execute a void based on these
values.
i am able to do the first 3 steps but i am stuck on the 4th step. To solve it i tried to use a loop:
foreach (TextBox tb in form1.Controls)
{
Response.Write(tb.Text);
}
but that throws an error:
Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.TextBox'.
how can i iterate throw the text-boxes?
thanks
Any static content is represented by a LiteralControl, which is why you experience that. A real easy way is to use LINQ:
var ctls = form1.Controls.OfType<TextBox>();
foreach (var ctl in ctls) { .. )
Or check the type as you loop through the controls to make sure it's a textbox first:
foreach (Control tb in form1.Controls)
{
if (tb is TextBox)
Response.Write(((TextBox)tb).Text);
}
Brian's answer seems a solid one. Another option that comes to mind at first sight is:
Declare a function...
Declare a simple array or even a string in js
Iterate from client side your inputs
And for each iteration you should be saving the value in that array or concatenating the value.
The array then can be saved as a string in some asp hiddenfield in order to do your server-side stuff.
Best regards.
Hi
In ASPxGridView, is there a way to get a row by its VisibleIndex or KeyValue so that I can change any column value in it?, I mean something like this:
var row = myGrid.SelectRowByKeyValue(myKeyValue);
OR:
var row = myGrid.SelectRowByVisibleIndex(myKeyValue);
row["Column1"] = true;
Edit:
What I'm tring to do is that every time I hit the button I want to check one specific row (I'm using ajax to not reload all the page);
Thanks
This can be done using the ASPxGridView.GetRow() method. NOTE, that changing the value in the DataRow is not enough. If you want these changes to be preserved, save them to the DB.
Since you are using unbound columns, you should handle the CustomUnboundColumnData event and provide modified data for this row within this event handler. The common approach is described in the Providing Data for Unbound Columns topic. If this does not help, please describe in greater details.
UPDATE
Your approach is incorrect. The ASPxGridView does not provide a method to set a text of a certain cell (TD). Instead, you should force the grid to raise the CustomUnboundColumnData event. This can be done using the ASPxGridView's DataBind method. In this event handler, you should determine the KeyField value of the processed row, compare it with the keyField value of the row where the button was clicked and return the required value. This is how I would implement this feature...
I solved it by using this code:
for (int i = 0; i < myGridView.VisibleRowCount; i++)
{
if ( [My condition] )
{
(
(CheckBox)myGridView
.FindRowCellTemplateControl(i,
myGridView.Columns["MyColumnName"] as GridViewDataColumn,
"My_Unbound_Control_Name"
)
).Checked = true;
}
}
I's may not be the right way to do it but I couldn't solve it another way.
I have a string which is ultimately the id of a CheckBox.
What I need to be able to do is to access the CheckBox's properties from the string
var myCheckBox:Object;
var myString:String;
myString = "checkbox_1"
myCheckBox = Object(myString); ?!?!
... and then I'd need to get to myCheckBox.selected, and myCheckBox.label etc
easier answer:
if(this.hasOwnProperty(myString) && this[myString] is CheckBox) {
myCheckBox = this[myString] as CheckBox
}
It's a bit of overcoding (since the as keyword will return a null if it's not a checkbox and you could better handle it that way with potentially less code), but that should do ya.
Best of luck.
If you know what DisplayObjectContainer (e.g. Sprite, MovieClip) the CheckBox is inside you can use getChildByName.
Unfortunately if you are using Flex containers (like Group) there is no function getElementByName(). There is getElementAt so you could write a loop that iterates over all of a Groups elements until it encounters one that matches the name you have.
I have a UI component that, for various reasons, I have to construct programatically. The component is a table of radio buttons grouped by column.
Right now, I'm constructing the column groups like so:
private function createGroupsForItemList(items: XMLList): void {
for each (var item: XML in items) {
var rbGroup: RadioButtonGroup = new RadioButtonGroup();
groups[item.#level.toString()] = rbGroup;
}
}
I'm trying to associate the RadioButton instances with the column groups like so:
private function createValueControl(item: XML): UIComponent {
var control: RadioButton = new RadioButton();
control.label = "";
control.group = groups[item.#level.toString()];
control.addEventListener(Event.SELECT, updateSelection);
return control;
}
I can see in the debugger that the control has an association to the group:
control.group == groups[item.#level.toString()]
However, I can see equally that the group does not know anything about the control:
group.radioButtons.length == 0
I imagine that this is because the setter for group in RadioButton is a dumb setter; all it does is copy to the variable, which doesn't do the magic that groupName does. However, I can't seem to find the value I should use to set the RadioButton.groupName property correctly.
So, in short, I'm stumped on how to get these bits to talk to each other. How do I do this?
-- EDIT --
It turns out that I can have the groups created and associated simply by setting the groupName property, but I can't get at the group to set up a selection listener; the group is NULL immediately after the setting process, which means that the second line below throws the Flex equivalent of an NPE:
control.groupName = groupNameForLevel(item);
control.group.addEventListener(Event.SELECT, updateSelection);
First instinct is that this issue has to do with invalidateDisplayList and when and how that is called. Of course, since issues related to that function are behind a number of Flex's quirks, I may just be scapegoating.
This is not the answer to your question per se, but it seems like it might actually work as an alternate solution.
RadioButtonGroups will initialize based on a IFlexDisplayObject. This means that you can do something like:
var c:HBox = new HBox();
var rbg:RadioButtonGroup = new RadioButtonGroup( c );
// do stuff with rbg.
c.addChild( new RadioButton() );
The problem is that it may not be the most practical answer, but it has the decided benefit of being a workable solution.
Setting groupName should work.
All I can suggest is to step through the group() getter of the RadioButton component and see where exactly it is failing. Are you programmatically creating the group too? If that's the case, maybe it isn't initialized fully yet.