I'm getting data into my code behind file in the format of array list. The sproc will return several records depending upon the input parameter value. Now i need to display all these values in HTML as labels dynamically.
For example if i got 2 records, i just need to display those 2 records, if 10 records are returned then display 10 records. I don't want keep 10 static labels to bind all the time. I just looking to place only one label in html and want to use that one to display all the records returned by query. Will it be possible??
Sample code:
//Client side
<asp:Label ID="lblresult" runat="server" CssClass="label" ></asp:Label>
//server side
Dim arraylist as arrayList = //result from sproc
Dim lbltext As String = ""
For Each item In arraylist
Do While item.value = lbltext
Me.lblresult.Text = item.value
lbltext = item.value
Loop
Next
Please let me how to solve this? Thanks in advance!
Kinda late for this, but is this what you are looking for?
For i = 0 To YourArrayList.Count - 1
lblresult.Text &= YourArrayList(i).ToString & " "
Next
Also this will cause you an error:
Dim arraylist as arrayList = //result from sproc
arraylist is a reserved keyword. You might want to use another name.
You can try following technique which i often use in C#,Php etc:
hope this will give you an idea for doing it in your programming Language.
string rows;
for(int cnt=0;cnt<array.count;cnt++) {
rows = rows +""+array[cnt].value;
}
yourLable.text = rows; //here you are binding all your rows to your lable
Related
I have a PostgreSQL table that stores some information in a JSON column, I'd like to take the data from this JSON column and populate a secondary table in the BIRT report.
I've got the data into a JSON object just fine, I can use it, but table #2 won't populate any data even though there is data in the JSON object.
DataSource1 it attached to DataSet1 which is PostgreSQL. DataSource2 is a scripted DS, and it has Dataset2 attached to it with columns defined.
In dataset1 I have the OnFetch function making my JSON array:
vars["invoiceData"] = JSON.parse(row["i_invoice"]);
Then I have in dataset2 (json dataset) I have this for the fetch event setup:
// Get the length of the object
len = vars["invoiceData"].labor.length;
count = 0;// Counter used to step through each item in the JSON object.
// Loop through the JSON object adding it to the scripted data source
if(count < len && len != 0) {
row["hrs"] = vars["invoiceData"].labor[count].hrs;
row["desc"] = vars["invoiceData"].labor[count].desc;
row["rate"] = vars["invoiceData"].labor[count].rate;
row["amount"] = vars["invoiceData"].labor[count].amount;
count++;
return true;
}
return false;
If I echo out the length of my array it has one row in it, but that table never comes back with anything, always empty on my report.
You are mixing initialization code with loop code.
Just think about this fragment:
count = 0;
if (...) {
count++;
return true;
}
return false;
You need to split and modify this code. Basically, for a scripted data set you need three things:
A counter variable (or something similar). This is best declared as a report variable.
Initialization of the counter variable in the data set's open event.
Using the counter variable in the data set's fetch event, eg modifying it and comparing it to the data length.
Your code will return the first data row in an endless loop, because what BIRT does is:
open()
while fetch():
emit the current row
Thus, your code is definitely wrong.
OTOH the behavior that you describe doesn't match what I would expect: A never-ending report. So there are probably other errors in your report. What does the "problems" view in the BIRT designer show?
I am attempting to write a tabular result (columns and rows of data) from an API call into an Excel range / table.
I managed to get it working, but I'd like for this to be dynamic across data sets (my data sets can be any shape with differing field names). As can be seen in the image, I don't necessarily know that the output is 3 columns of data, but I would want to get this from the JsonResult object (it forms part of the object, but I don't know how to access / reference it).
The object also contains the column names of the data which I would like written to Excel as well (as headings), but I don't know how.
Finally I'd like to write the row data to Excel as well, but I don't know how to access these values without specific reference to them (e.g. "company_code").
TO SUMMARISE: The items in yellow in the screenshot as well as the column / field names should be dynamically read from the JsonResult object.
Any assistance would be appreciated.
JsonResult in text: "[{"company_code":"ABC","employee_code":"5","is_exception":"0"},{"company_code":"ABC","employee_code":"8","is_exception":"1"}]"
My code snippet (if it helps):
Set JsonResult = ParseJson(ParseJson(req.responseText)("results")(1)("findings"))("results")
Dim Values As Variant
ReDim Values(JsonResult.Count, 3)
Dim Value As Dictionary
Dim i As Long
i = 0
For Each Value In JsonResult
Values(i, 0) = Value("company_code")
Values(i, 1) = Value("employee_code")
Values(i, 2) = Value("is_exception")
i = i + 1
Next Value
Sheets("Sheet1").Range(Cells(1, 1), Cells(JsonResult.Count, 3)) = Values
This is what ended up working for me:
Dim Item As Dictionary
Dim i As Long, size As Long
size = UBound(JsonResult(1).Keys) + 1
[a1].Resize(, size) = JsonResult(1).Keys 'Header rows
i = 1
For Each Item In JsonResult
i = i + 1
Range("A" & i).Resize(, size) = Item.Items 'Result rows
Next Item
The keys from the collection / dictionary's first Item is used for the Header rows and the items from each item in the collection / dictionary is written to Excel after that.
Works like an absolute charm.
I am building a report in SSRS and wondering how to show the value in the column 2 rows before. I have used the Previous expression to retrieve the one before, but now I need the one before that.
Any help would be much appreciated
Thank you
Sam
Shared Dataset looks like this:
https://i.stack.imgur.com/Ii5y6.jpg
You can use custom code to set and get the value.
Public Dim Previous2 As String
Public Dim Previous As String
Public Function SetPrevious2 ( s As String) As String
Previous2 = Previous
Previous = s
Return Previous2
End Function
For the cell use and expression like the one below
= Code.SetPrevious2(Previous(Fields!MyValue.Value))
I have a select that I get Json post with http, but I try to sets initially selected index but there is nothing in the list do not select anything. because the json is great.
public AppMainScreen() {
loadLists();
MySelect = new ObjectChoiceField( "Select: ", new Object[0], 3 );
VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL);
vfm.add(MySelect);
add(vfm);
}
This statement appears wrong to me:
new ObjectChoiceField( "Select: ", new Object[0],3);
The second parameter to this constructor is supposed to be an array of objects whose .toString() method will be used to populate the choices. In this case, you have given it a 0 length array, i.e. no Objects. So there is nothing to choose. And then you have asked it to automatically select the 3rd item, and of course there is no 3rd item.
You should correct the code to actually supply an object array.
One option to make it easy is have your JSON load actually create a String array with one entry per selectable item. Then you use the index selected to identify the chosen item.
I had a similar question before, but this is a few steps beyond that so here we go:
I am trying to access values in a category in Tridion 2011. I am using the Razor TBB and using this code to do it:
#foreach (var keyword in Publication.MetaData.myCategory) {
#: Hello World!
}
I have set up a metadata schema with a field that has an xml name of "myCategory" attached to my publication. If I run this on the publication where myCategory is a Text field, this code works... kind of. It treats EACH character as a separate value of the keyword variable... so if I enter the text "one", what prints is "Hello World! Hello World! Hello World!", and if I just have "o" as the value, it prints "Hello World!".
Bizarre as that is (and I'd like to know why on that too), what I really want the field to be a "Values will be selected from a list" type of field, pointing to my category in Categories and keywords. When I do this, and the value of myCategory changes to the value of the item selected in the dropdown for this type of field instead of direct text entry, the code no longer works and gives this error:
Cannot implicitly convert type 'Tridion.Extensions.Mediators.Razor.Models.KeywordModel' to 'System.Collections.IEnumerable'. An explicit conversion exists (are you missing a cast?)
Please help me.
If you get your output repeated for every character in a string, you are clearly iterating over the characters in the string and not the other range of values that you expected.
I quickly checked the relevant code of the Razor mediator and its ToString method indeed returns the Title of the underlying RepositoryLocalObject.
http://code.google.com/p/razor-mediator-4-tridion/source/browse/trunk/Tridion.Extensions.Mediators.RazorMediator/Tridion.Extensions.Mediators.RazorMediator/Models/AbstractRepositoryLocalObject.cs
http://code.google.com/p/razor-mediator-4-tridion/source/browse/trunk/Tridion.Extensions.Mediators.RazorMediator/Tridion.Extensions.Mediators.RazorMediator/Models/KeywordModel.cs
http://code.google.com/p/razor-mediator-4-tridion/source/browse/trunk/Tridion.Extensions.Mediators.RazorMediator/Tridion.Extensions.Mediators.RazorMediator/Models/DynamicItemFields.cs
The code that handles KeywordFields in in the DynamicItemsFields.cs file:
else if (itemField is KeywordField)
{
KeywordField keywordField = (KeywordField)itemField;
if (keywordField.Definition.MaxOccurs == 1)
if (keywordField.Value == null)
_dictionary[key] = null;
else
_dictionary[key] = new KeywordModel(_engine, keywordField.Value);
else
{
List<KeywordModel> keywords = new List<KeywordModel>();
int i = 0;
foreach (Keyword k in keywordField.Values)
{
var kw = new KeywordModel(_engine, k);
kw.Index = i++;
kw.IsLast = Index == keywordField.Values.Count - 1;
keywords.Add(kw);
}
_dictionary[key] = keywords;
}
}
So it looks like the myCategory property will either be a KeywordModel object (if the KeywordField is single-value) or a List<KeywordModel> (if the KeywordField is marked as multi-value in the Schema). Is your myCategory field single value? Or multi-value?
If it is single-value, what type of output were your expecting? If you were expecting the list of allowed values (instead of the currently selected value), check if you can access it through myCategory.Definition somehow (which should be a regular TOM.NET KeywordFieldDefinition object).