I am trying to find a way bind Grid view to a JSON.NET parsed Linq to Json object
simply am calling
JObject yrs = SearchData("");
then use one property to be bound to Grid view
GridView1.DataSource = yrs["businesses"].Children();
I cant find any resources for something like that
neither binding directly work nor using Children, and seems like I can not find it in the documentation.
appreciate your help
I think I just needed to sleep :)
this is how it should go, if someone need that ,
var bsn =from c in yrs["businesses"].Children()
select new { Title = (string)c["Title"] , Type = (string)c["Type"] };
GridView1.DataSource = bsn;
if there are better ways please advice
Related
I've been messing around with CM conventions trying to understand how they work but i haven't found a decent article somewhere explaining step-by-step how and why.
However I've found a few code snippets that i've been working with with some success.
In this case, however, i don't understand what is going on.
I'm trying to bind a NumericUpDown Value and Maximum to a corresponding ViewModel property. I was able to do it with the following code:
Value
ConventionManager.AddElementConvention<NumericUpDown>(NumericUpDown.ValueProperty, "Value", "ValueChanged");
Maximum
ConventionManager.AddElementConvention<NumericUpDown>(NumericUpDown.MaximumProperty, "Maximum", "MaximumChanged");
var baseBindProperties = ViewModelBinder.BindProperties;
ViewModelBinder.BindProperties =
(frameWorkElements, viewModels) =>
{
foreach (var frameworkElement in frameWorkElements)
{
var propertyName = frameworkElement.Name + "Max";
var property = viewModels.GetPropertyCaseInsensitive(propertyName);
if (property != null)
{
var convention = ConventionManager.GetElementConvention(typeof(NumericUpDown));
ConventionManager.SetBindingWithoutBindingOverwrite(
viewModels,
propertyName,
property,
frameworkElement,
convention,
convention.GetBindableProperty(frameworkElement));
}
}
return baseBindProperties(frameWorkElements, viewModels);
};
However, an here comes the weird part, i can only make one of them to work. That makes me believe that i'm doing some noob mistake somewhere. It almost seems i can only call AddElementConvention and therefor only the last call is executed.
I would appreciate either a help with this piece of code or a reference to some good documentation that could help me with it.
Best Regards
i found out somewhere that CM only allows one convention per item so that's the reason of this behavior...
However since items like ComboBox allows binding for multiple properties (SelectedItem, ItemSource and so on...) i'm not completed convinced...
I have been trying for a long time to fix the bugs I'm encountering with my dropdownlists in my project. I'm getting data this with at the moment and it's working fine:
using (InfoEntities ie = new InfoEntities())
{
var sqlddl = (from query in ie.Table_Customers
from q in ie.Accounting_PriceType
where query.TypeID == 1 && q.ID == 1
orderby query.Customers
select query).Distinct().ToList();
DropDownListCust.DataTextField = "Customers";
DropDownListCust.DataValueField = "ID";
DropDownListCust.DataSource = sqlddl;
DropDownListCust.DataBind();
}
Now when the user saves the data and opens the website again I need the saved value that was chosen on the dropdownlist earlier retreived. This also works fine but the problem is I'm getting duplicates. Anyways I'm doing it like this and I'm pretty sure I'm doing it wrong:
On the page load i load my dropdownlist to get all the items plus the following to get the saved value:
DropDownListCust.SelectedItem.Text = sql.Customers;
This makes my DDL very buggy, some items dissapear and also sometimes dupicated values. Can anyone please help? I'm using LINQ but I can use some other methods as long as it's fixed.
Cheers
I solved my problem like this:
DropDownList1.ClearSelection();
DropDownList1.Items.FindByText(sql.Customer).Selected = true;
I've got a JObject (using JSON.Net) that I created by parsing some JSON text. I'm directly manipulating, adding keys at the top level of this JObject. I have no problems when the value I'm adding is a string:
json["newkey"] = "New Value"; // works
But I'll be damned if I can figure out how to add a Dictionary, e.g.:
Dictionary<string,string> dict = new Dictionary<string,string>();
dict["one"] = "1";
dict["two"] = "2";
json["dict"] = dict; // fails
I've done quite a bit of googling and reading the JSON.Net docs, but everything seems oriented towards reason JSON text into a JObject, or writing .NET objects as JSON text using serialization. Or using some fancy LINQ statements to do all kinds of things with complex objects...
I've tried these and none have worked:
json["dict"] = new JObject(dict);
json["dict"] = new JObject((Dictionary<string,string>)dict);
json["dict"] = new JArray(dict); // desperation sets in :)
json["dict"] = (JObject)dict; // please dear god let this work
Most of the latest errors I encounter are:
Could not determine JSON object type for type System.Collections.Generic.KeyValuePair`2[System.String,System.String].
I believe that you are looking for something like this:
json["dict"] = JObject.FromObject(dict);
There is a desperate "hack" that you can use, it's not pretty (doing twice the same thing) but it works :)
json["dict"] = JObject.Parse(JsonConvert.SerializeObject(dict));
this is my first time to ask here since my question is not answerable in the adobe flex forum. So at least finally, I've come to manage it here.
Well, Flex 4.5+ is I guess everyone is working on nowadays so I asked this question since I haven't yet find working both spark datagrid and the mx printdatagrid components together.
What I'm trying to achieve is to print all the data inside my spark datagrid. So when I do my research, we use the PrintJob or the FlexPrintJob classes. It works fine but when I need to print multiple pages since the data on my spark datagrid is quite long, I can't somehow find a way how to do it. The print output is only upto where the height of my spark datagrid. So in my research, they somehow managed it to use the mx:PrintDataGrid component. But sad to say, they did it with an mx:DataGrid also. Now here comes my problem - how to use the mx:PrintDataGrid along with s:DataGrid.
var printJob:PrintJob = new PrintJob();
if (printJob.start())
{
var printGrid:PrintDataGrid = new PrintDataGrid();
printGrid.width = printJob.pageWidth;
printGrid.height = printJob.pageHeight;
printGrid.columns = mySparkDataGrid.columns; // this line throws an exception
printGrid.dataProvider = mySparkDataGrid.dataProvider;
printGrid.visible = false;
FlexGlobals.topLevelApplication.addElement(printGrid);
while (printGrid.validNextPage)
{
printGrid.nextPage();
printJob.addPage(printGrid);
}
printJob.send();
parentApplication.removeElement(printGrid);
}
So please, can anyone here help me with this? If converting a spark datagrid columns to the mx datagrid columns is not possible, is there a way that I can print all the data on the spark datagrid using multiple pages?
Big thanks in advance.
-Ted
Try somethink like this(it works to me)
for (var i:int = 0; i < mySparkDataGrid.columns.length - 1; i++) {
var tmpColumn:DataGridColumn = new DataGridColumn();
tmpColumn.headerText = (mySparkDataGrid.columns.getItemAt(i) as GridColumn).headerText;
tmpColumns.push(tmpColumn);
}
printGrid.columns = tmpColumns;
Now i have to find way,how use ItemRender.My dataprovider has bigger object and I have to parse it for display correct data in grid.The same I have to do for print.
(Note, the code below are just examples. Please don't comment on the why this is necessary. I would appreciate a definitive answer of YES or NO, like if it is possible then how? If not it's fine too. If the question is vague let me know also. Thanks!)
Example, I can get ObjectSet<T> below:
ObjectSet<Users> userSet = dbContext.CreateObjectSet<Users>();
ObjectSet<Categories> categorySet = dbContext.CreateObjectSet<Categories>();
The code above works okay. However, I need the entity table to be dynamic so I can switch between types. Something like below.
//var type = typeof(Users);
var type = typeof(Categories);
Object<type> objectSet = dbContext.CreateObjectSet<type>();
But the code above will not compile.
[EDIT:]
What I'd like is something like, or anything similar:
//string tableName = "Users";
string tableName = "Categories";
ObjectSet objectSet = dbContext.GetObjectSetByTableName(tablename);
I've got this working with the following tweak to the suggestions above:
var type = Type.GetType(myTypeName);
var method = _ctx.GetType().GetMethod("CreateObjectSet", Type.EmptyTypes);
var generic = method.MakeGenericMethod(type);
dynamic objectSet = generic.Invoke(_ctx, null);
Can you use the example here in How do I use reflection to call a generic method?
var type = typeof(Categories); // or Type.GetType("Categories") if you have a string
var method = dbContext.GetType.GetMethod("CreateObjectSet");
var generic = method.MakeGenericMethod(type);
generic.Invoke(dbContext, null);
I have found the answer here, http://geekswithblogs.net/seanfao/archive/2009/12/03/136680.aspx. This is very good because it eliminates having multiple repository objects for each table mapped by EF particularly for mundane operations like CRUD, which is exactly what I was looking for.