I am doing some labeling. I would like to add a resource key (s, sec) to one of my combo boxes with item[3sec, 5sec, 10sec, 30sec ...] and use it like:
Text="3<%$ Resources: myResource, s%>" to get comboBoxItem 3sec,
Text="5<%$ Resources: myResource, s%>" to get comboBoxItem 5sec ...
But I find that the server will treat this as plain text.
Do I need to define each item in a separate resource key pair?
Consider defining your resource file entry value as follows:
{0}sec
And then
String.Format(Resources.myResource.s, "3")
You can try creating your own custom expression builder. They are really powerful if you want to achieve what you have asked in your question.
Or, you can always do it using server-side code.
You could do it like this (with a DataBind() call somewhere):
Text='<%# "3" + Resources.myResource.s %>'
Edit: You can also do this from code behind. Something like this:
int[] times = new int[]{ 3, 5, 10, 30 };
foreach (int time in times)
{
string text = time.ToString() + Resources.myResource.s;
cbo.Items.Add(new ListItem(text, time.ToString()));
}
Edit 2: As per Muhammad's observation the first example doesn't work for this. I've used it for other controls, and I didn't see that for the current case it's not correct. Given this I would fill the control from code behind.
Related
I am working on a report in AX 2009. I want to filter data of InventSiteID on the basis of ExpDate.
I have 2 datasource in the query which is attached to report. Both the data source are same InventExpired. I have to show 4 fields in dialog i.e. SiteID, Exp Date for datasource1 and same for datasource 2 and then filter it out.
In your report, you can use
SysQuery::findOrCreateRange(this.queryRun().query().dataSourceNo(1),
fieldNum(InventExpired, ExpDate)
).value(SysQuery::value(yourFilterDate));
That will filter the first datasource with the date entered.
If you need to filter by dates greater than or less than the filter date, you can use
SysQuery::findOrCreateRange(...).value('>' + SysQuery::value(yourFilterDate));
or
SysQuery::findOrCreateRange(...).value('<' + SysQuery::value(yourFilterDate));
Do you know how to add the fields to the dialog?
If you don't, you should override the dialog() method, and in the dialog() method, after the call to super(), you should use:
Dialog d = ret;
expDateField = d.addField(typeid(yourDateEDT), "Expiry Date");
To get the values from the fields and use them in your report, you should use
expDateField.value()
I haven't tested this, but I've done similar things on numerous occasions so I'm fairly confident this will work. Let me know if you have any problems with this
If you want to specify a range here is how I accomplished it. Hope this helps somebody...
Method1:
qbds3 = qry.dataSourceTable(tableNum(DMxVehicleTable));
SysQuery::findOrCreateRange(qbds, fieldNum(DMxVehicleTable,VehicleMSRPRetails)).value(strFmt('(VehicleMSRPRetails >= %1) && (VehicleMSRPRetails <= %2)', queryValue(VehicleMinPrice), queryValue(VehicleMaxPrice)));
Method2:
qbds4 = qry.dataSourceTable(tableNum(DMxSysYearTable));
SysQuery::findOrCreateRange(qbds4, fieldNum(DMxSysYearTable,Year), 1, 1).value('>' + SysQuery::value(VehicleModelYearStart));
qbds4.addRange(fieldNum(DMxSysYearTable, Year)).value(strFmt('< %1', queryValue(VehicleModelYearEnd)));
I have a quick question about JQuery. I have dynamically generated paragraphs with id's that are incremented. I would like to take information from that page and bring it to my main page. Unfortunately I am unable to read the dynamically generated paragraph IDs to get the values. I am trying this:
var Name = ((data).find("#Name" + id).text());
The ASP.NET code goes like this:
Dim intI As Integer = 0
For Each Item As cItem in alProducts1
Dim pName As New System.Web.UI.HtmlControls.HtmlGenericControl("p")
pName.id = "Name" & intI.toString() pName.InnerText = Item.Name controls.Add(pName) intI += 1
Next
Those name values are the values I want...Name1, name2, name3 and I want to get them individually to put in their own textbox... I'm taking the values from the ASP.NET webpage and putting them into an AJAX page.
Your question is not clear about your exact requirement but you can get the IDs of elements with attr method of jQuery, here is an example:
alert($('selector').attr('id'));
You want to select all the elements with the incrementing ids, right?
// this will select all the elements
// which id starts with 'Name'
(data).find("[id^=Name]")
Thanks for the help everyone. I found the solution today however:
var Name = ($(data).find('#Name' + id.toString()).text());
I forgot the .toString() part and that seems to have made the difference.
Is it possible to specify MXML-esque "binding strings" in ActionScript?
For example, I want to be able to do something like:
MXMLBinding(this, "first_item",
this, "{myArrayCollection.getItemAt(0)");
MXMLBinding(this, ["nameLbl", "text"],
this, "Name: {somePerson.first} {somePerson.last}");
Edit: thanks for the responses and suggestions… Basically, it seems like you can't do this. I've dug around and figured out why.
(Shameless plug)
BindageTools can do this:
Bind.fromProperty(this, "myArrayCollection", itemAt(0))
.toProperty(this, "first_item");
Bind.fromAll(
Bind.fromProperty(this, "somePerson.first"),
Bind.fromProperty(this, "somePerson.last")
)
.format("Name: {0} {1}")
.toProperty(this, "nameLbl.text");
Note that BindageTools puts the source object first and the destination last (whereas BindingUtils puts the destination first and the source last).
Using ChangeWatcher (e.g., via BindingUtils.bindProperty or .bindSetter) is the way to go, yes. I admit it's a strange notation, but once you get used to it, it makes sense, works perfectly and is quite flexible, too.
Of course, you could always wrap those functions yourself somehow, if the notation bugged you -- both methods are static, so doing so in a way that feels more appropriate to your application should be a fairly straightforward exercise.
I could use BindingUtils or ChainWatcher, but then I'd end up with code that looks something like this:
…
BindingUtils.bindSetter(updateName, this, ["somePerson", "first"]);
BindingUtils.bindSetter(updateName, this, ["somePerson", "last"]);
…
protected function updateName(...ignored):void {
this.nameLbl.text = "Name: " + somePerson.first + " " + somePerson.last;
}
Which is just a little bit ugly… And the first example, binding to arrayCollection.getItemAt(0), is even worse.
Does the first parameter (function) of BindingUtils.bindSetter method accept anonymous methods?
BindingUtils.bindSetter(function()
{
this.nameLbl.text = "Name: " + somePerson.first + " " + somePerson.last;
}, this, ["somePerson", "last"]);
I hate anonymous methods and obviously it's even more uglier - so I won't recommend that even if it works, but just wondering if it works.
Never the answer anyone wants to hear, but just manage this stuff with getters/setters in ActionScript. With a proper MVC, it's dead simple to manually set your display fields.
public function set myArrayCollection(value:Array):void {
myAC = new ArrayCollection(value);
first_item = mcAC.getItemAt(0); // or value[0];
}
etc....
Alright, so I've done some digging, and here's what's up.
Bindings in MXML are, contrary to reason, setup by Java code (modules/compiler/src/java/flex2/compiler/as3/binding/DataBindingFirstPassEvaluator.java, if I'm not mistaken) at compile time.
For example, the binding: first_item="{myArrayCollection.getItemAt(0)}"` is expanded into, among other things, this:
// writeWatcher id=0 shouldWriteSelf=true class=flex2.compiler.as3.binding.PropertyWatcher shouldWriteChildren=true
watchers[0] = new mx.binding.PropertyWatcher("foo",
{ propertyChange: true }, // writeWatcherListeners id=0 size=1
[ bindings[0] ],
propertyGetter);
// writeWatcher id=1 shouldWriteSelf=true class=flex2.compiler.as3.binding.FunctionReturnWatcher shouldWriteChildren=true
watchers[1] = new mx.binding.FunctionReturnWatcher("getItemAt",
target,
function():Array { return [ 0 ]; },
{ collectionChange: true },
[bindings[0]],
null);
// writeWatcherBottom id=0 shouldWriteSelf=true class=flex2.compiler.as3.binding.PropertyWatcher
watchers[0].updateParent(target);
// writeWatcherBottom id=1 shouldWriteSelf=true class=flex2.compiler.as3.binding.FunctionReturnWatcher
// writeEvaluationWatcherPart 1 0 parentWatcher
watchers[1].parentWatcher = watchers[0];
watchers[0].addChild(watchers[1]);
This means that it is simply impossible to setup curly-brace MXML-style bindings at runtime because the code to do it does not exist in ActionScript.
I am trying to display the results of a search on a gridview.
I want the search to show the results for both last and first name.
I am using ASP.NET with Subsonic and can't figure out how to modify the statemnt below.
I am guessing it needs a wildcard somewhere?
Name: <asp:TextBox ID="txtSearchName" runat="server"></asp:TextBox>
GridView1.DataSource = new Select(PastAwardName.Schema.TableName + ".*", PastAwardType.Schema.TableName + ".*")
.From(PastAwardName.Schema)
.InnerJoin(PastAwardType.Schema.TableName, PastAwardType.Columns.VolID, PastAwardName.Schema.TableName, PastAwardName.Columns.VolID)
.Where(PastAwardName.Columns.LName).IsEqualTo(this.txtSearchName.Text)
.Or(PastAwardName.Columns.FName).IsEqualTo(this.txtSearchName.Text)
.OrderAsc(PastAwardType.Columns.AwardYear)
.ExecuteDataSet();
I think that should work.
Are you familiar with getting the generated SQL from that query?
SubSonic.SqlQuery q = new Select(PastAwardName.Schema.TableName + ".*", PastAwardType.Schema.TableName + ".*")
.From(PastAwardName.Schema)
.InnerJoin(PastAwardType.Schema.TableName, PastAwardType.Columns.VolID, PastAwardName.Schema.TableName, PastAwardName.Columns.VolID)
.Where(PastAwardName.Columns.LName).IsEqualTo(this.txtSearchName.Text)
.Or(PastAwardName.Columns.FName).IsEqualTo(this.txtSearchName.Text)
.OrderAsc(PastAwardType.Columns.AwardYear);
string sql = q.BuildSqlStatement();
Check the value of sql (with a breakpoint on that line) to provide further clues into the problem.
For the wildcard - use the ContainsString() method instead of hardcoding a wildcard like so:
.Where(PastAwardName.Columns.LName).ContainsString(this.txtSearchName.Text)
This will automatically add the provider-specific wildcard character to the beginning and end of the parameter. You can also do StartsWith() and EndsWith().
<asp:Repeater ID="rptLessons" runat="server">
<ItemTemplate>
<tr>
<td><%#Eval("fullname")%></td>
<td><%#isCompleted(Eval("totallessons"), Eval("completedlessons"), Eval("totalNumAvail"), Eval("totalNumCorrect"))%></td>
<td><%#FormatPercent(Eval("totalnumcorrect") / Eval("totalNumAvail"))%> <%-- (<%#Eval("totalnumcorrect")%> / <%#Eval("totalNumAvail")%>) --%></td>
<td><%#FormatPercent(Eval("completedlessons") / Eval("totallessons"))%> <%-- (<%#Eval("completedlessons")%> / <%#Eval("totallessons")%>) --%></td>
<td><%#Eval("lastaccessed")%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
I can't figure it out but as soon as it hits some NULL data it refuses to move on to drawing the next elements.
You need to give a stack trace to be sure.
But I can see several issues:
DIV#0 errors inside FormatPercent
NULL errors.
Example Solution
(System.Convert.ToInt32 should convert DBNull/NULL to 0)
Or alter isCompleted to accept Object paramters and do your NULL / DBNull checking inside the function.
On slightly different approach that might be helpful would be to do your computations in your code behind rather than inline in the markup. Just easier to check for nulls etc. I almost always go down this path with anything other than a simple Eval() in my markup.
<td>
<%#GetCorrectPercent()%>
</td>
protected string GetCorrectPercent()
{
if(Eval("totalnumcorrect") == null || Eval("totalNumAvail") == null)
return "n/a";
return ((int)Eval("totalnumcorrect") / (int)Eval("totalNumAvail")).ToString();
}
Not sure all the formatting is correct here but this should get you going in a different direction. Eval() will work within the called methods so long as the caller is current performing a DataBind().
If I had to guess, I would say that your isCompleted function doesn't handle values of Nothing. This is a guess because the function hasn't been listed in your example.
I tend more towards the explicit. Forgive any minor mistakes in the code, I'm not able to test this.
If in your markup you swap out those evals for literals then in the code behind:
If you have a collection of MyClass.
In your page's init event
this.rptLessons.OnItemDataBound += rptLessons_DataBound...
In the load or where ever you choose
this.rptLessons.DataSource = CollectionOfMyClass;
this.rptLessons.DataBind();
Then in that itemDataBoundEvent
MyClass myClass = (MyClass)ri.DataItem;
Literal litFullname = FindControl(ri, "litFullName");
litFullName.Text = myClass.Fullname;
This way you can cater for nulls etc in a more controlled way than using eval.