I am trying to create a Repeater Template User Control i.e. a rectangular border contains a row of UIElements Like TextBox, ComboBox etc and then I'm automatically adding a + button at the end of the Row. On + button Click I want to add the Same duplicate row below it.
This is the Syntax making use of User Control:
<RepeaterTemplate>
<RepeaterTemplateItem>
<TextBox />
<ComboBox />
</RepeaterTemplateItem>
</RepeaterTemplate>
CODE BEHIND:
RepeaterLayoutItem:
Public Grid RepeaterRow { get; set; }
Public List LayoutItemCollection { get; set; }
//On + button click handler:
RepeaterLayoutItem duplicate = this.memberWiseClone();
LayoutItemCollection.Add(duplicate);
RepeaterLayout :
public ObservableCollection Children { get; set; }
public Grid RepeaterContentGrid { get; set; }
foreach(RepeaterLayoutItem item in Children)
{
Grid duplicateRow = item.RepeaterRow;
RepeaterContentGrid.Children.Add(duplicateRow); //Here it gives error "Element is already child of other element" on + button click.
}
I also tried it with ICloneable interface, but still same issue.
If I duplicate the row using the memberWiseClone(), still on adding the duplicate row I'm getting the same error. May be bceause of non-null value of Parent property in the cloned duplicate row.
I don't know how to get this functionality working. Please HELP.
Thanks,
GK Prajapati
I allowed the WAMS wizard to create the "test" table ("Items") it so congenially offers to create after setting up my WAMS.
Then I wanted to create a table that will actually be useful to me. The instructions in the wizard do say, "You can add and remove tables later by using the "Data" tab above."
So I did that, and I did create a table, but I can't see now where I can change the structure of the table (IOW, add columns). I've tried 2-clicking the service, 2-clicking the table, selecting the "New" button, right-clicking on the sole column name (id) in my table, etc., but all to no avail.
Something I'm confused about, too, is the relationship of the tables I create this way with my existing SQL DB tables - or can I do without that SQL DB now (once I get these WAMSical tables set up)?
Or why can't I associate my existing SQL DB tables to my WAMS? And if I can -- how?
UPDATE
Also, it seems there is a mismatch between what is written and what I'm actually experiencing. This (from http://msdn.microsoft.com/en-us/magazine/jj721590.aspx) is not true/did not happen for me:
"2.Create a relational table to store your data. When you click on the Create TodoItem Table button, the wizard will automatically create a table based on the Windows Azure SQL Database you created (or re-used) previously."
I tried "from scratch," creating a new WAMS. Again, I get when I select my existing SQL DB, "Database and Mobile Service Not in the Same Region - Performance will decrease...Additionally, the data sent from the db to the mobile service will be counted as billable bandwidth usage. We recommend that you choose a database in the same location as the mobile service."
I would like to, but how? Why didn't WAMS adjust this for me automatically - or at least give me the option to put my DB and Mobile Service in the same place?
UPDATE 2
What is interesting is that I CAN see the new tables in LINQPad. I already had two SQL DB tables that display under that connection info, but on the same level as those tables is my WAMS name, under which are the "default" Items table and one of my own I created (both of which, though, only have one column, specifically "Id (Int64)"
IOW, what I see in LINQPad is:
blaBlaBla.database.windows.net,1433.blaBla
BlaBla
BlaBlaSQLDB_Table1
BlaBlaSQLDB_Table2
wamsName
Items
Id (Int64)
BlaBlaWAMSTable
Id (Int64)
...so how do I extend/manage the "BlaBlaWAMSTable" is the problem now...
UPDATE 3
Well, looky here; LINQPad to the rescue again:
select * from <WAMSName>.<TableName>
...shows there is a record after I created the table I wanted via a class in my project (NOT in the Azure/WAMS management area)
...and, of course, LINQPad shows the newly added columns added that way.
All I needed to do was follow the steps provided (Reference the Azure SDK, add a corresponding using clause, etc.) and then added this method to test it out:
private async void InsertTestRecordIntoWAMSSQLDBTable()
{
<WAMS Table class name> invitation = new <WAMS Table class name> { SenderID = "donkeyKongSioux#supermax.gov", ReaderDeviceID = "00-AA-11-BB-01-AB-10-BA", ReaderName = "B. Clay Shannon", SenderUTCOffset = 5, SenderDeviceID = "BA-10-AB-01-BB-11-AA-00" };
await App.MobileService.GetTable<<WAMS Table class name>>().InsertAsync(invitation);
}
...and it worked. Now it would be nice to have some samples/examples for select queries as well as updates.
And my big remaining question (so far): can I decorate/annotate the columns/members of my table class? IOW, can I change this:
public class
{
public int Id { get; set; }
public string SenderID { get; set; }
public string ReaderDeviceID { get; set; }
public string ReaderName { get; set; }
public int SenderUTCOffset { get; set; }
public string SenderDeviceID { get; set; }
}
...to something like this:
public class
{
[Primary, AutoInc]
public int Id { get; set; }
[Indexed]
public string SenderID { get; set; }
[Unique]
public string ReaderDeviceID { get; set; }
[MaxLength(255)]
public string ReaderName { get; set; }
public int SenderUTCOffset { get; set; }
public string SenderDeviceID { get; set; }
}
?
I can't do exactly that, as those are SQLite annotations, but since I am unable to manage my table from the Azure/WAMS portal, how can I designate these attributes?
After altering the design of the table in code, I'm able to see that those columns have been added to my table in the WAMS portal, but it seems the only thing I can do to the columns is add an index...
UPDATE 4
It turns out that creating tables in WAMS is as easy as pie (but not as easy as pi/as hard as pi) - once you know how to do it.
With the WAMS created, select Data, and then Create to create a table. Give it a name, and select the permissions you want. This will give you a deadly dull but "living" database table with one, count 'em, one, column: ID, a BigInt, indexed.
THEN, to actually add more columns to the table, the easiest way I've found (the only way I've found that is, and it is easy) is to:
1) Create a class that corresponds to the database table, a la SQLite, such as:
public class WAMS_DUCKBILL
{
public int Id { get; set; }
public string PlatypusID { get; set; }
public DateTime UpdateTimeUTC { get; set; }
public double Income { get; set; }
public double Outgo { get; set; }
}
2) Write a method that will add a record to this table, such as:
private async void InsertTestRecordIntoWAMSDuckbillTable()
{
WAMS_DUCKBILL duckbill = new WAMS_DUCKBILL { PlatypusID = "42", UpdateTimeUTC =
DateTime.Now, Income = 3.85, Outgo = 8311.79 };
await MobileService.GetTable<WAMS_DUCKBILL>().InsertAsync(duckbill);
}
3) Call that method from App.xaml.cs' OnLaunched event
4) As can then be seen by running the following query in LINQPad (or however you want to pee[k,r] into the database):
SELECT * FROM platypi.WAMS_DUCKBILL
Call me old fashioned, but notice I'm using tired old SQL as opposed to LINQ here; so sue me. At any rate, LINQPad shows that the test record has indeed been inserted into the WAMS table. Voila! as the escargot-eating, beret-at-a-rakish-angle wearing cats say.
The focus for Windows Azure Mobile Services (WAMS) are app developers who does not want to invest a lot of time to develop a backend. Therefor the data model easier than you might think.
Tables in WAMS are always backed by tables in a SQL database. You can create and delete tables via the portal.
Creating columns is a bit different. You create columns by simply using them. As soon as you write data for a column that does not exist, WAMS creates that column automatically. That's called Dynamic Schema. After development you should disable Dynamic Schema. You find it in the Mobile Service, Configure.
Documentation: Data access in Windows Azure Mobile Services
Just trying to do some quick and dirty testing. I am passing fake data through my controller to a view just to see how the UI looks.
In my controller which I set up just to "test" this I have, for example:
MyViewModel = new MyViewModel
{
MyModel= new Models.MyModel
{
FirstName = "Homer", //This works
SomeDecimal = 10000, //This works
SomeRadioButton = Models.MyModel.Enum.Selection, //This works
SomeCheckBox = Models.MyModel.OtherEnum.OtherSelection, //This doesn't
}
}
I am getting the Cannot implicitly convert type ... to 'System.Collections.Generic.List<string>' error.
My radio buttons and check boxes share similar convention for using enums, but the checkbox uses public List<string> SomeCheckBox { get; set; } whereas radio buttons use public Enum? SomeRadioButton { get; set; }
Please note, I am not using a testing framework. I am just trying to figure out quickly how to pass some fake data to see how the UI is shaping up. Can anyone share a sample of how to accomplish what I want (to pass a checkbox value so my UI can show data that would have been selected by a user)?
The other problem I forsee is in passing more than one selection from the checkbox, but once I get the code down I think I should be able to figure that out.
Thanks.
Your error message makes total sense. Try this
var testViewModel = new TestViewModel
{
SomeCheckBox = new List<string> {TestViewModel.RadioButtonValues.Value1.ToString() }
};
I am developing a Widget to show Content pushes on the home page. The push model is as below.
public class PushRecord : ContentPartRecord
{
public virtual string Header { get; set; }
public virtual string Text { get; set; }
public virtual string Url { get; set; }
}
On the admin, I modified the ContentType of the Push Widget to add Media Picker Field. I would like to make a hyper link around the image with Url provided by PushPart. Npw the widget is rendered by two templates, Parts.Push.cshtml and Fields.MediaPicker-PushWidget-Image.cshtml. How do I merge these two and make my Push rendering possible? Any help is greatly appreciated.
Maybe try suppressing display of mediapickerfield via placement.info, and then explicitly render the image with the hyperlink from the .cshtml of the PushPart. You can access the MediaPickerField url like this:
#{
var pushPart = Model.ContentPart;
var photoUrl = pushPart.MediaPickerFieldName.Url;
}
<img src="#photoUrl" ... />
In a ASP.NET MVC 4 app I have a view with a paged list (just a simple table, no telerik grid or anything like that). New values are fetched from the database when the user pages through the list.
On every row in that table there is an edit button, when clicking the button you are presented with an edit view and when you click save in that view you are redirected back to the view with the paged list.
The urls for the list view looks like this
http://localhost/Items/Page/1
http://localhost/Items/Page/2
The route looks like this
routes.MapRoute(
name: "ItemsList",
url :"Items/Page/{page}",
defaults: new { controller = "Items", action = "Index", page = 1 },
constraints: new {page = #"\d+"}
);
My question is this: what is the preferred, most common way to store away the referring url, so when done editing an item, I can redirect the user back to the correct url
http://localhost/Items/Page/2
and not just to
http://localhost/Items
I've tried splitting up
Request.UrlReferrer.PathAndQuery
and storing those values around, and then build the url from those values but I have a feeling there is a much better solution to this problem. Any suggestions?
Update
Right now I'm thinking that I could put the UrlReferrer.PathAndQuery (if there are any values) as a property on the view model for the edit screen and then use that when deciding on where to redirect after a save.
Any thoughts out there on that approach?
Here is my final solution to the problem, it's not super elegant but it works.
I added a property to the View model that could store the url. That value get's stored in a hidden field.
public class SkillEditModel
{
public int Id { get; set; }
public string Name { get; set; }
public string RedirectBackToUrl { get; set; }
}
In the controller Edit(GET) method I store the value with the view model
if (!Request.UrlReferrer == null)
{
model.RedirectBackToUrl = Request.UrlReferrer.PathAndQuery;
}
And finally after saving the changes in Edit (POST) I did this
if (!string.IsNullOrWhiteSpace(model.RedirectBackToUrl))
{
return new RedirectResult(model.RedirectBackToUrl);
}
return RedirectToAction("Index");